Data Validation on Form linked to SQL table

  • Thread starter Thread starter OsmoseTom
  • Start date Start date
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?
 
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.
 
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.
 
Back
Top