CranstonSnord
New member
- Local time
- Today, 01:04
- Joined
- Feb 29, 2024
- Messages
- 10
Note to all responders: This is purely a home learning database and there is no desperate corporate urgency to answer the question.
I have a simple test form that I use to help me determine event order when following a specific set of steps on the form, i.e., a "happy path" for data entry.
I've set up each event for the form with a conditional compilation argument code block that looks like this (of course changing the print statement to match each event):
Private Sub Form_Activate()
#If Testing = 1 Then
Debug.Print "frmTest Activate Event"
#End If
End Sub
I then open the form, enter the data in the order I need to test for, and review what the immediate window tells me as to the order of events. The process I am currently trying to code for is as follows.
txtALBUM_TITLE textbox BeforeUpdate Event
txtALBUM_TITLE textbox AfterUpdate Event
frmTest BeforeUpdate Event
frmTest Error Event
frmTest Error Event
frmTest Undo Event
frmSubTest txtTRACK_TITLE Exit Event
txtALBUM_TITLE textbox Exit Event
txtALBUM_TITLE textbox LostFocus Event
frmTest Unload Event
frmTest Deactivate Event
frmTest Close Event
frmSubTest Form Unload Event
frmSubTest Form Close Event
All 3 of the text boxes on the form (ALBUM_ID, ALBUM_TITLE, and RELEASE_YEAR) are required fields in the table that the form is bound to. During a normal data entry event, I rely on the form's BEFORE UPDATE event to test to ensure that these 3 controls are all populated prior to moving on to the sub form. However, in this test case I'm simulating the user (me) abandoning the data entry process. What I would like to have happen is for Access to post a message that says something to the effect of, "You have unsaved content. Select Continue to proceed or Quit to abandon your changes."
My problem is, I can't figure out how to trap for the clicking on the "Close" button. There are no errors thrown until the ERROR event is reached, and although I can trap for those errors there, I still get a message from my BEFORE UPDATE event that the RELEASE_YEAR control hasn't been populated. I need a way to programmatically determine that the "Close" button has been clicked, but none of the form events above (including CLICK, MOUSE DOWN, MOUSE UP, etc.) fire prior to the form's BEFORE UPDATE event.
Is there a way to immediately know that the "Close" button has been selected so that I can divert the program flow past the validations I've built into the BEFORE UPDATE event? For form simplicity sake I would prefer not to have to add a "Close" command button, but if that's the only way around this situation then so be it.
I have a simple test form that I use to help me determine event order when following a specific set of steps on the form, i.e., a "happy path" for data entry.
I've set up each event for the form with a conditional compilation argument code block that looks like this (of course changing the print statement to match each event):
Private Sub Form_Activate()
#If Testing = 1 Then
Debug.Print "frmTest Activate Event"
#End If
End Sub
I then open the form, enter the data in the order I need to test for, and review what the immediate window tells me as to the order of events. The process I am currently trying to code for is as follows.
- I enter an album ID, then <Tab> to the next control on the form.
- I enter a simple title.
- I click on the "Close" button in the upper right corner of the form.
txtALBUM_TITLE textbox BeforeUpdate Event
txtALBUM_TITLE textbox AfterUpdate Event
frmTest BeforeUpdate Event
frmTest Error Event
frmTest Error Event
frmTest Undo Event
frmSubTest txtTRACK_TITLE Exit Event
txtALBUM_TITLE textbox Exit Event
txtALBUM_TITLE textbox LostFocus Event
frmTest Unload Event
frmTest Deactivate Event
frmTest Close Event
frmSubTest Form Unload Event
frmSubTest Form Close Event
All 3 of the text boxes on the form (ALBUM_ID, ALBUM_TITLE, and RELEASE_YEAR) are required fields in the table that the form is bound to. During a normal data entry event, I rely on the form's BEFORE UPDATE event to test to ensure that these 3 controls are all populated prior to moving on to the sub form. However, in this test case I'm simulating the user (me) abandoning the data entry process. What I would like to have happen is for Access to post a message that says something to the effect of, "You have unsaved content. Select Continue to proceed or Quit to abandon your changes."
My problem is, I can't figure out how to trap for the clicking on the "Close" button. There are no errors thrown until the ERROR event is reached, and although I can trap for those errors there, I still get a message from my BEFORE UPDATE event that the RELEASE_YEAR control hasn't been populated. I need a way to programmatically determine that the "Close" button has been clicked, but none of the form events above (including CLICK, MOUSE DOWN, MOUSE UP, etc.) fire prior to the form's BEFORE UPDATE event.
Is there a way to immediately know that the "Close" button has been selected so that I can divert the program flow past the validations I've built into the BEFORE UPDATE event? For form simplicity sake I would prefer not to have to add a "Close" command button, but if that's the only way around this situation then so be it.