I'm banging my head against the wall over something I thought would be simple! I have a form that that opens to the last record. I then want the "txt_ReferenceDate" field to be checked to see if it matches the current date. If it does the form should open normally to the last record. If it doesn't a yes/no message box should ask if the user wishes to create a new record (Yes) or continue of with the last record (No). I've tried using the following code:
Code:
Private Sub Form_Load()
DoCmd.GoToRecord , , acLast
If Me.txt_ReferenceDate <> Date Then
If MsgBox("This record is not for the current date. Would you like to create a new record?", vbYesNo, "Warning!") = vbYes Then
DoCmd.GoToRecord , , acNewRec
Else
Exit Sub
End If
End If
End Sub
If I answer no everything works as expected. If I answer yes I get the dreaded 2499 error stating I cannot use the GoToRecord in design view(??). I've tried the code in both the OnLoad and OnCurrent events. I get the same results using the OnCurrent event except the message box comes up twice before either opening the form or giving me the 2499 error depending on the selection.
I know the user could just manually advance to a new record after opening the form without being prompted. The purpose of the message box is to force the user to think about what they are doing rather than just blindly charging ahead. Thanks for any and all help!