Validations

D

Dinger188

On a form, I have a combo box with a list of "Nature of Calls" and 2
additional combo boxes labeled Type of Fire and Cause of fire. If
"Fire" is
picked from the nature of call I would like to validate that the Type
of Fire
and Cause of Fire was completed. What I came up with works, but only
when
"Fire" is not picked. How do I do this correctly??

Here is what I have:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Const conBtns As Integer = vbOKOnly + vbCritical + vbDefaultButton2 +
vbApplicationModal
Dim intUserResponse As Integer

If IsNull(Me.Date) Then
Cancel = True
intUserResponse = MsgBox("Complete the INCIDENT DATE Field!", conBtns,
"STOP! Incomplete Field")
Me.Date.SetFocus

ElseIf IsNull(Me.Nature_of_Call) Then
Cancel = True
intUserResponse = MsgBox("Complete the NATURE OF CALL Field!", conBtns,

"STOP! Incomplete Field")
Me.Nature_of_Call.SetFocus

ElseIf IsNull(Me.Called_By) Then
Cancel = True
intUserResponse = MsgBox("Complete the CALLED BY Field!", conBtns,
"STOP!
Incomplete Field")
Me.Called_By.SetFocus

ElseIf (Me.Nature_of_Call) = "Fire" Then

ElseIf IsNull(Me.Type_of_Fire) Then
Cancel = True
intUserResponse = MsgBox("Complete the TYPE OF FIRE Field!", conBtns,
"STOP!
Incomplete Field")
Me.Type_of_Fire.SetFocus

ElseIf IsNull(Me.Cause_of_Fire) Then
Cancel = True
intUserResponse = MsgBox("Complete the CAUSE OF FIRE Field!", conBtns,
"STOP! Incomplete Field")
Me.Cause_of_Fire.SetFocus

End If

End Sub
 
T

tina

you don't need the intUserResponse variable, because it isn't used anywhere
in the procedure. also, if you really have a field called "Date" in your
table, recommend you change it. see
http://home.att.net/~california.db/tips.html#aTip5 for more information.

try the following, as

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strMsg As String

If IsNull(Me!Date) Then
Cancel = True
strMsg = "INCIDENT DATE"
Me!Date.SetFocus
ElseIf IsNull(Me!Nature_of_Call) Then
Cancel = True
strMsg = "NATURE OF CALL"
Me!Nature_of_Call.SetFocus
ElseIf IsNull(Me!Called_By) Then
Cancel = True
strMsg = "CALLED BY"
Me!Called_By.SetFocus
ElseIf (Me!Nature_of_Call) = "Fire" Then
If IsNull(Me!Type_of_Fire) Then
Cancel = True
strMsg = "TYPE OF FIRE"
Me!Type_of_Fire.SetFocus
ElseIf IsNull(Me.Cause_of_Fire) Then
Cancel = True
strMsg = "CAUSE OF FIRE"
Me!Cause_of_Fire.SetFocus
Else
Exit Sub
End If
Else
Exit Sub
End If

MsgBox "Complete the " & strMsg & " Field!", _
vbOKOnly + vbCritical + vbDefaultButton2 + vbApplicationModal, _
"STOP! Incomplete Field"

End Sub

hth
 
D

Dinger188

Thanks... I got it corrected. Now I have a new question / Problem....

I'd like to validate
the date range in the date (now incident date) field. I can get it to
work
with a validation rule but I'd like to use an event procedure. Here is
what I
came up with:

***Start***

Const conBtns As Integer = vbOKOnly + vbCritical + vbApplicationModal
Dim intUserResponse As Integer

If (Me.IncidentDate) >= #4/1/2006# And <#4/1/2007# Then
Cancel = True
intUserResponse = MsgBox("CORRECT THE INCIDENT DATE!" & Chr(13)
& Chr(10) & Chr(13) & Chr(10) & "Between 4/1/2006 and 3/31/2007",
conBtns, "STOP! Date Not in Range")
Me.IncidentDate.SetFocus

End If

End Sub


***End***

I get a error, "Complie error: Expected: expression" and it highligts
"<"

What did I do wrong??
 

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