On Exit event code

G

Guest

I have a login form which has On Exit event code for user initials and
password fields. This code traps invalid data or no data entered by the
user. But I also want to allow the user the option of exiting from the login
screen if they so chose, without first entering valid data in either of these
fields. However, if the user enters nothing and just clicks on the Abort
button, then the On Exit code of the field their cursor is in fires before
anything else and they are not allowed to exit without first entering valid
data. How can I allow them to exit without entering any data?
 
K

Ken Snell [MVP]

Decide how the form will know the difference between invalid data and no
data. After you decide that, you then can code the Exit event procedure to
make that same decision.

For example, if the control is empty, perhaps you would not do the
validation:

Private Sub ControlName_Exit(Cancel As Integer)
If Len(Me.ControlName.Value & "") > 0 Then
' put your validation code here
End If
End Sub
 
B

Brendan Reynolds

Private Sub Text0_Exit(Cancel As Integer)

If Len(Me!Text0 & vbNullString) = 0 Then
Cancel = MsgBox("You have not entered any text in this text box. " &
_
"Are you sure you want to continue?", vbYesNo) = vbNo
End If

End Sub
 
G

Guest

Thanks for answer, but I see I didn't make myself clear enough. This is a
login screen/form. The user cannot proceed unless valid data is entered into
both initials and password fields. So, invalid data and no data must be
treated the same in both Exit events.

The problem comes in trying to allow the user to abort the login screen
altogether by clicking an Abort command button, no matter what they have
entered (or not entered) for initials and password. When the user clicks on
the Abort button: The problem is that the Exit event procedure of the field
where the cursor is sittiing is being executed before the Abort button
procedure. The user is trapped and cannot Abort unless they first enter
valid data, which they may not be able to do.

ctdak
 
K

Ken Snell [MVP]

Then you'll need to use a different event for doing data validation. You
won't be able to use the Exit event if you must treat "no entry" and
"invalid entry" the same in that event. Can you use the form's Before Update
event to test for this (this occurs just before the form saves the data to
its recordsource)? Or can you use the click event of a button that the user
clicks to save the data and close the form?
 
G

Guest

This form has no recordsource. However, you have confirmed what I was just
realizing is probably the only solution - to use the Click event of a button
that the user clicks to proceed into the application from this login form. I
have relocated my data validation code to such an event and it works pretty
well. If the user's data is blank or not valid, then the focus is set back
to that control for them to try again.

Thanks for your responses.
ctdak
 

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