Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation of Data depends upon other fields

Status
Not open for further replies.

paulnnosh

MIS
Mar 25, 2004
32
Hi,

I have a form with several text boxes. When I click the save button I'd like to run some code to check that if the status field is set to "C" that the closed details are also populated.

I have the following IF statement:

If Me.Status = "C" Then

If Me.cboClosedCode = Null Then

MsgBox "If the prospect is closed you must enter a closed code and closed details"

End If

End If

However when I run this it still saves the record. I know this is because once I click OK on the msgbox the processing just carries on. Is there anyway I can stop it?

Thanks for any help.
 
use the exit sub to stop running code at that point. like this:

If Me.Status = "C" Then

If IsNull(Me.cboClosedCode) Or Me.cboClosedCode = "" Then

MsgBox "If the prospect is closed you must enter a closed code and closed details"
Exit Sub ' Stops here.
End If

End If
 
Hi!

You should use the Before Update Event Procedure:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Me.Status = "C" Then

If Me.cboClosedCode = Null Then

MsgBox "If the prospect is closed you must enter a closed code and closed details"
Cancel = -1
End If

End If

The Cancel = -1 cancels the save procedure.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top