Data Validation on Form linked to SQL table

O

OsmoseTom

Can someone please help me?

I created a form called Communicaiton Needs Survey. The form is linked to a
SQL server table called Communication Survey. We are using a SQL table so
that multiple users can enter data simultaneously.

I would like to require data in a field (CurrentCellPhoneProvider) if a
check box (CurrentCellPhone) is checked.

Here is the code I am using:

Private Sub Current_Cell_Phone_Provider_BeforeUpdate(Cancel As Integer)
If Me.CurrentCellPhone = True Then
If IsNull(Me.CurrentCellPhoneProvider) Then 'No entry was made
MsgBox "If Cell Phone box is checked you must enter the cell phone
provider.", vbInformation, _
"Missing Current Cell Phone Provider..."
Cancel = True
Me.CurrentCellPhoneProvider.SetFocus
End If
End If
End Sub

The issue I am having is that when the CurrentCellPhone checkbox is checked
I can tab past the CurrentCellPhoneProvider field without the msg box
appearing?
 
S

Scott Lichtenberg

Tom,

Move the code to the BeforeUpdate event of the form. The Cancel=True
statement will prevent the record from updating if the record fails
validation.
 
O

OsmoseTom

Scott, I tried moving the code. I am still getting the same result? Any
other ideas?
 
O

OsmoseTom

Nevermind Scott, I hade a typo in the code. Moving it worked perfectly.
Thanks for your help. I can't believe I missed this easy fix.
 

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