I have a main form that will always be opened first when someone is working in my db, called "fAssessment". Another form, called "fDefineDefaults", allows the user to edit any of the default values before they start working in fAssessment. I recently set it up so that when you open fAssessment for the first time it opens fDefineDefaults and waits for that to close before it continues with any code. Assuming it's the first time the user is opening fAssessment, this SHOULD open fDefineDefaults and wait for it to be closed before doing anything else. After fDefineDefaults is closed, fAssessment will prompt the user for some more information, and then the user can begin working in fAssessment.
However..
For some reason this is not the order in which these events take place. The code that opens fDefineDefaults was occurring where it should (first), until I added a simple 'If' statement to check if it needed to be opened or not. After doing this, it completely skipped over that if statement and starts prompting the user for the additional information I mentioned earlier.
I thought this was because I constructed my If statement wrong, but...
If the user doesn't enter valid input, or clicks cancel, the code moves back up to the initial prompt via a 'GoTo'. What's REALLY strange is that if this occurs, instead of going back to the spot defined by GoTo, it goes back up to the top and opens fDefineDefaults and continues where it should have after fDefineDefaults is closed.
This doesn't make any sense, because if the code that opens fDefineDefaults is ran, then that means the if statement was true and it should have occurred before anything else.
The Code:
Code:
If IsNull(DLookup("Size", "tRAMSize")) Or DLookup("Size", "tRAMSize") = 0 Then
DoCmd.OpenForm "fDefineDefaults", , , , , acDialog <------------- This is the line that opens fDefineDefaults and waits for it to be closed before continuing.
End If
If DLookup("Size", "tRAMSize") > 0 Then
Exit Sub
End If
Re_Prompt:
Rsize = InputBox("Please Enter RAM dimensions") <----------- This is the line the code starts on, for some reason.
'Ends process if user clicks 'cancel' or gives no input, and checks if input is a number
If Rsize = "" Then
MsgBox "Dimension selection was canceled", vbOKOnly
Exit Sub
ElseIf IsNumeric(Rsize) Then
Rsize = CInt(Rsize)
db.Execute "INSERT INTO tRAMSize(Size)" & "VALUES(" & Rzie & ")"
Else
MsgBox "Please only enter a number for RAM dimensions"
GoTo Re_Prompt
End If
I've tried adding MsgBox's to see what was happening, and even the MsgBox I placed at the very top of the sub was completely skipped. This MsgBox is displayed when the 'GoTo' gets used. (Note that I removed these msgbox's before posting to clean up the code a bit)
It should also be mentioned that this code was working 100% as intended prior to me adding the line to open fDefineDefaults. Adding those lines is the only thing that has changed since it started acting strange.
Hopefully I explained that well enough. I'd be happy to provide any additional details if necessary.
Any help is greatly appreciated.
UPDATE:
I tried adding the line that opens fDefineDefaults to the if statement that executes if the user enters an appropriate input for the additional information, i.e. it should execute that before it updates tables with the user input. For some reason this still doesn't cause the form to open, almost as if it's just ignoring the line while its in an if statement. To test this I placed the line in an If that will always be true (If 1 = 1 Then) and it ran fine. Not sure whats causing it to be ignored everywhere except where I don't need it to be.
I also added more MsgBox's throughout the sub to try to understand what process it goes through. From what I discovered, it prompts for input before doing anything else and then immediately jumps back to the top. I stopped the code before it could continue after moving back to the top of the sub, and checked my table that the user input is stored in. Somehow, the input was stored in a table without me telling it to do so yet (unless it's ignoring my MsgBox's until it jumps to the top?). The messages that I set to appear before and after updating the table with user input never appeared, so I'm assuming it never executed the UPDATE command. That being said it doesn't make any sense that it would be saved to the table without being told to save it there..
I'm seriously stumped on this one..