"Before update" question

  • Thread starter Thread starter Bob Quintal
  • Start date Start date
B

Bob Quintal

=?Utf-8?B?c2N1YmFkaXZlcg==?=
I have three combo boxes in a form

Act_Dept
Act_Subd
Act_User

The 2nd and 3rd have the following code:

If IsNull(Me!Act_Subd) Then
MsgBox "You must fill in the subdepartment",
vbCritical Cancel = True
Me!Act_Subd.SetFocus
End If


If IsNull(Me!Act_User) Then
MsgBox "You must fill in the user name", vbCritical
Cancel = True
End If

Now I only want these codes to fire when Act_Dept is not null.
I have tried added an extra line but it doesn't seem to work.

If Me!Act_Dept <> Null and IsNull(Me!Act_Subd) Then
MsgBox "You must fill in the subdepartment",
vbCritical Cancel = True
Me!Act_Subd.SetFocus
End If

Cheers

If MeAct_dept!<> null will not work
Replace it with
If (Not isnull(Me!Act_Dept)) AND isnull)Me!Act_Subd_ then
 
I have three combo boxes in a form

Act_Dept
Act_Subd
Act_User

The 2nd and 3rd have the following code:

If IsNull(Me!Act_Subd) Then
MsgBox "You must fill in the subdepartment", vbCritical
Cancel = True
Me!Act_Subd.SetFocus
End If


If IsNull(Me!Act_User) Then
MsgBox "You must fill in the user name", vbCritical
Cancel = True
End If

Now I only want these codes to fire when Act_Dept is not null. I have tried
added an extra line but it doesn't seem to work.

If Me!Act_Dept <> Null and IsNull(Me!Act_Subd) Then
MsgBox "You must fill in the subdepartment", vbCritical
Cancel = True
Me!Act_Subd.SetFocus
End If

Cheers
 
scubadiver said:
I have three combo boxes in a form

Act_Dept
Act_Subd
Act_User

The 2nd and 3rd have the following code:

If IsNull(Me!Act_Subd) Then
MsgBox "You must fill in the subdepartment", vbCritical
Cancel = True
Me!Act_Subd.SetFocus
End If


If IsNull(Me!Act_User) Then
MsgBox "You must fill in the user name", vbCritical
Cancel = True
End If

Now I only want these codes to fire when Act_Dept is not null. I have
tried added an extra line but it doesn't seem to work.

If Me!Act_Dept <> Null and IsNull(Me!Act_Subd) Then
MsgBox "You must fill in the subdepartment", vbCritical
Cancel = True
Me!Act_Subd.SetFocus
End If

Cheers

You cannot use = or <> to test for null. You have to use...

IsNull(...)
or
Not IsNull(...)
 
Try:
If Not IsNull (Me.Act_Dept) and IsNull(Me.Act_Subd) Then
etc.

You didn't say in which event the code occurs, but if the user never enters
the combo box its code won't have a chance to run. If you programatically
send the user to the combo box, and the user then exits the combo box
without making a selection, the code won't run either. The Form's Before
Update event is generally a good place to perform validation, although it
could be in the Change or Enter event of another control.
 
Check your syntax:
If (Not isnull(Me!Act_Dept)) AND isnull)Me!Act_Subd_ then
If Not IsNull(Me.Act_Dept) And IsNull(Me.Act_Subd) Then
 

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

Back
Top