Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating record when user nagivates away

Status
Not open for further replies.

dotolee

Technical User
Jan 27, 2008
134
CA
Hi there.

In my Form_Current() event, i have some logic that looks like:

If StudyNo.Value = Null Then
MsgBox ("Missing Study Number.")
Exit Sub
End If

If txtInterviewDate.Value = Null Then
MsgBox ("Missing interview date. Use the calendar control to select an interview date.")
Exit Sub
End If

What I'd like to see happen is when the user tries to navigate away from the current record using the VCR controls created by the wizard, this code is executed first thing.

What's happening is that these messages don't appear, but the message from the system is appearing after a long while - stating that certain fields are mandatory. (based on my table design).
What am i doing wrong?
thanks.
 
When you leave the record whose data has changed, but before you enter the next record, the Exit and LostFocus events occur for the control with the focus. These events occur after the BeforeUpdate and AfterUpdate events for the form, as follows:

BeforeUpdate (form) ? AfterUpdate (form) ? Exit (control) ? LostFocus (control) ? RecordExit (form) ? Current (form)

Try using the forms Before Update event since the current event happens after access checks for a required value.
 
Anyway, replace such things:
If AnyName.Value = Null Then
with something like this:
If Trim(AnyName.Value & "") = "" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
MajP, thanks for the details. I appreciate that tip.
I did try the beforeupdate before i tried the current... but it behaves the same way...
 
dotolee . . .

In the forms [blue]BeforeUpdate[/blue] event, copy'paste the following:
Code:
[blue]   If Trim(Me!StudyNo & "") = "" Then
      MsgBox ("Missing Study Number.")
      Me!StudyNo.SetFocus
      [purple][b]Cancel = True[/b][/purple]
   ElseIf Trim(Me!txtInterviewDate & "") = "" Then
      MsgBox ("Missing interview date. " & _
              "Use the calendar control to select an interview date.")
      Me!txtInterviewDate.SetFocus
      [purple][b]Cancel = True[/b][/purple]
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top