Code problem

S

Steve

Hi, I am having trouble with the following code.

I have a field called ClearanceCode and six different date/times fields. If
the clearance code is completed and one of the date/time fields isn't i want
a message box to display that the date/times fields need to be completed.

I can get the code to work on an individual clearnce code but want it to
work just if the Clerance code is complete as I have about 20 different
clearance codes. ie "OU","NHA","RIC" etc

Heres the code
If Me![Clearancecode] = "OU"
And IsNull(Me![Timerec'd@customer]) = True Then
MsgBox"Please fill in the date/time fields"
Cancel = True

Cheers Steve
 
D

Dirk Goldgar

Steve said:
Hi, I am having trouble with the following code.

I have a field called ClearanceCode and six different date/times
fields. If the clearance code is completed and one of the date/time
fields isn't i want a message box to display that the date/times
fields need to be completed.

I can get the code to work on an individual clearnce code but want it
to work just if the Clerance code is complete as I have about 20
different clearance codes. ie "OU","NHA","RIC" etc

Heres the code
If Me![Clearancecode] = "OU"
And IsNull(Me![Timerec'd@customer]) = True Then
MsgBox"Please fill in the date/time fields"
Cancel = True

It seems to me that the basic code would be:


If Not IsNull(Me![Clearancecode]) Then
If IsNull(Me![Timerec'd@customer]) Then
Cancel = True
MsgBox"Please fill in the date/time fields"
Me![Timerec'd@customer].SetFocus
End If
End If

However, there's some question as to where such a test should go. I
prefer to allow users to move freely about the form and update controls
in whatever sequence they prefer, only doing record-level validation
when the record is about to be saved. That means that code like this
would go in the form's BeforeUpdate event. Is that the way you have it
set up?
 
S

Stephen Milner

Dick

I have the code set in the forms BeforeUpdate event. Thanks for the info,
much appriciated.

Steve


Dirk Goldgar said:
Steve said:
Hi, I am having trouble with the following code.

I have a field called ClearanceCode and six different date/times
fields. If the clearance code is completed and one of the date/time
fields isn't i want a message box to display that the date/times
fields need to be completed.

I can get the code to work on an individual clearnce code but want it
to work just if the Clerance code is complete as I have about 20
different clearance codes. ie "OU","NHA","RIC" etc

Heres the code
If Me![Clearancecode] = "OU"
And IsNull(Me![Timerec'd@customer]) = True Then
MsgBox"Please fill in the date/time fields"
Cancel = True

It seems to me that the basic code would be:


If Not IsNull(Me![Clearancecode]) Then
If IsNull(Me![Timerec'd@customer]) Then
Cancel = True
MsgBox"Please fill in the date/time fields"
Me![Timerec'd@customer].SetFocus
End If
End If

However, there's some question as to where such a test should go. I
prefer to allow users to move freely about the form and update controls
in whatever sequence they prefer, only doing record-level validation
when the record is about to be saved. That means that code like this
would go in the form's BeforeUpdate event. Is that the way you have it
set up?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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