Stuck .... Can't exit form

T

TeeSee

Private Sub CustomerIDCode_Exit(Cancel As Integer)
If IsNull(Me!CustomerIDCode) Then

MsgBox "You must enter a Customer Code before entering other
data!"

End If
'Me.CustomerIDCode.SetFocus
Cancel = True

End Sub

On the above form there are two text controls, one of which is
[CustomerIDcode]. When I place the cursor in the other control the
MsgBox appears as expected. I first tried the "SetFocus" but read in a
post that that caused conflict .... so changed it to Cancel=True which
works as expected. The problem arises when (assuming) the user does
not have the appropriate [CustomerIDCode] and decides to "bail" then
clicks the command button on the form to cancel the transaction with
the following code .....

Private Sub Command23_Click()
If (Me.Dirty = True) Then
Me.Undo
End If
' And close me
DoCmd.Close acForm, Me.Name
End Sub

I now have two questions.
1) The command button is obviously a control on the same form and
since I try to enter it the message box appears as usual. how would I
exclude the cancel command button from the MsgBox code?
2) A Is the form "Dirty" the instand I place the cursor in the second
control or does there actually need to be input?

Thanks as usual.
 
A

Allen Browne

The immediate solution is to undo the record.
Press <Esc>, or click the Undo button (toolbar) twice.
This gets you out.

In any case, you need to move this code into the BeforeUpdate event of the
*form*. If the user never visits this control (e.g. they click on another
one and just bypass it), then its Exit event will not fire, and so your code
will not run.
 

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