I have a piece of code which runs when a user leaves the last control on a form. The code displays a message box which asks the user whether they want to add a new record (select yes). Selecting no will display a second message box, which asks whether they want to exit database (yes) or close this form (no). Everything works fine except I cannot get the form to close!
The Code is:
Private Sub frame_Exit(Cancel As Integer)
Dim Msg, Style, Title, Response, MyString
Msg = "Do you want to add a new record? " ' Define message.
Style = vbYesNo + vbExclamation + vbDefaultButton1 ' Define buttons.
Title = "End of record" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
DoCmd.GoToControl "accession_no"
DoCmd.GoToRecord , , acNewRec
'MyString = "Yes" ' Perform some action.
Else
Msg = "Do you want to close the database? Select yes to close, no to return to the start of this record" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "End of record" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes
DoCmd.Close acform "frm_objects" (this is the bit that doesnt work!"
Else
DoCmd.GoToControl "accession_no"
End If
End If
End Sub
Please if anyone can help I will be forever grateful - I do not understand why this code is not working!
Many many thanks
Emma
The Code is:
Private Sub frame_Exit(Cancel As Integer)
Dim Msg, Style, Title, Response, MyString
Msg = "Do you want to add a new record? " ' Define message.
Style = vbYesNo + vbExclamation + vbDefaultButton1 ' Define buttons.
Title = "End of record" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
DoCmd.GoToControl "accession_no"
DoCmd.GoToRecord , , acNewRec
'MyString = "Yes" ' Perform some action.
Else
Msg = "Do you want to close the database? Select yes to close, no to return to the start of this record" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "End of record" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes
DoCmd.Close acform "frm_objects" (this is the bit that doesnt work!"
Else
DoCmd.GoToControl "accession_no"
End If
End If
End Sub
Please if anyone can help I will be forever grateful - I do not understand why this code is not working!
Many many thanks
Emma