Populate text box before Exiting form

C

CAM

Hello,

In my form there are several text boxes, combo boxes, etc. Below is an
example of my code that I use to make sure that the user fully populates
combo boxes on the form. The code is in the Form_BeforeUpdate. Here is my
problem if the user click on the exit button without populating all the
combo boxes (in this example the received date and assigned to) they will
get the message box what has not been populated and the program will exit
before the user can populate the combo boxes. I want to make sure that the
user get the message and populate the combo boxes based on the error message
box and then exit. How can this be done? Any tips will be appreciated.
Thank you in advance.


Private Sub Form_BeforeUpdate(Cancel As Integer)

'Verify if received date has been entered
ElseIf IsNull(Me.[cboReceivedDate]) Then
Cancel = True
MsgBox "Enter received date."

'Verify if Assigned To is Not Null
ElseIf IsNull(Me.[comboAssignedTo]) Then
Cancel = True
MsgBox "You must input assigned to."

End Sub



Code for exiting program

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

'Exit system
DoCmd.Quit
Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub
 
S

Svetlana

Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click

If Me.Dirty=True Then
Me.Refresh
Else
'Exit system
DoCmd.Quit
End If

Exit_cmdExit_Click:
Exit Sub

Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top