Validation Rule Code Help

V

vmf

I am using the following code in my form but it isn't producing a message box
when tabbing to a new record. I think the problem might be with the "And"
but I'm not sure. Any help would be appreciated.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If Me.Combo36 = "P" And IsNull(Me.BegSeqNum) Then
Cancel = True
strMsg = strMsg & "Beginning Sequence Number required." & vbCrLf
End If

If Me.BegSeqNum > 0 And IsNull(Me.EndSeqNum) Then
Cancel = True
strMsg = strMsg & "End Sequence Number required." & vbCrLf
End If

If Cancel Then
strMsg = strMsg & "Correct the entry, or press Esc to undo."
MsgBox strMsg, vbExclamation, "Invalid data"
End If


End Sub
 
M

Marshall Barton

vmf said:
I am using the following code in my form but it isn't producing a message box
when tabbing to a new record. I think the problem might be with the "And"
but I'm not sure. Any help would be appreciated.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If Me.Combo36 = "P" And IsNull(Me.BegSeqNum) Then
Cancel = True
strMsg = strMsg & "Beginning Sequence Number required." & vbCrLf
End If

If Me.BegSeqNum > 0 And IsNull(Me.EndSeqNum) Then
Cancel = True
strMsg = strMsg & "End Sequence Number required." & vbCrLf
End If

If Cancel Then
strMsg = strMsg & "Correct the entry, or press Esc to undo."
MsgBox strMsg, vbExclamation, "Invalid data"
End If
End Sub


Unless you want to check for other kinds on invalid entries,
there isn't anything obviously wrong with your code. Try
placing a breakpoint in there to verify the values of the
two controls.
 
V

vmf

Thank you Mr. Barton, but could you tell me what a breakpoint is & how to
include it in my code?
 
M

Marshall Barton

vmf said:
Thank you Mr. Barton, but could you tell me what a breakpoint is & how to
include it in my code?


Open your form in design view. Then use the View - Code
menu item to see the form's code in the VBA window. Click
in the left margin gray area next to the line where you want
Access to stop processing (the line should be highlighted
probably in dark red).

Then go back to your form and change it to form view. Enter
whatever data you need to trigger the code and when it stops
at the selected line, you can see the value of the controls
just by hovering the mouse over the name in the code. Check
the combo box to make sure it contains a "P", etc.

IMPORTANT - Do not edit the code while the form is displayed
in form view. Change the form to design view before editing
any code.
 

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

Similar Threads


Top