Code question (1 Viewer)

Peter Paul

Registered User.
Local time
Today, 04:40
Joined
Jan 1, 2000
Messages
82
Greetings,
I am working on a form which needs to prompt the user to enter data based on specific information. Part of the data looks to see

If Me.Code = "220" And Me.LocationOfOffense = "14" Or Me.LocationOfOffense = "19" And IsNull(Me.PremisesEntered) Then
Cancel = True
MsgBox "message here"
Else
DoCmd.GoToRecord , , acNewRec
Me.OffenseNumber.SetFocus

This gets the user to the field PremisesEntered.

Now I want to insist that they user enter data in this box. So in the On Exit property I want to look to see if the field is empty. If it is, then they should either have to enter data, or return to the Code field to change the data that got them to that point. What I have tried is not working:
If Me.Code = "220" And Me.LocationOfOffense = "14" Or Me.LocationOfOffense = "19" And IsNull(Me.PremisesEntered) Then
MsgBox "Click OK to enter the number of premises entered, or change the Offense Code or Cancel to change the data input", vbOKCancel, "CRIMES Information - Breaking and Entering"
If Cancel Then Me.Code.SetFocus
If OK Then
Me.PremisesEntered.SetFocus
End If
End If

Any help, as always, is greatly appreciated.

Peter Paul
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:40
Joined
Feb 19, 2002
Messages
43,368
Since the user can use the mouse to enter any field on the form in any order, it is fruitless to try to stop him unless of course you're into writing code. The best place to put edits that depend on multiple fields, is the BeforeUpdate event of the form. This event is the last one fired before the data is actually inserted or updated. And, it is fired no matter how the user tries to exit. As long as Access recognizes that the form is "dirty", it will attempt to save the data before leaving the current record.

If any errors are found, you can cancel the event and display an appropriate message.
 

Users who are viewing this thread

Top Bottom