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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation doesn't work?

Status
Not open for further replies.

mymou

Technical User
May 21, 2001
355
GB


Hi

I'm using the BeforeUpdate event to validate data (catch nulls). This works fine unless a user happens to enter data and then delete it. Error 2108 generated.

Can someone explain what is happening?

Thanks in advance
Stewart

--------------------


Private Sub txtControl_BeforeUpdate(Cancel As Integer)

Dim iAns As Integer
Dim strMsg As String

If IsNull(Me!txtControl) Then
strMsg = "txtControl should be entered. Click OK to do so, Cancel" _
& " to leave it blank anyway:"
iAns = MsgBox(strMsg, vbOKCancel)
If iAns = vbOK Then
Cancel = True
Me!txtControl.SetFocus
End If
End If

End Sub


 
You may replace this:
If IsNull(Me!txtControl) Then
with this:
If Trim(Me!txtControl & "") = "" Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
BTW, get rid of this: Me!txtControl.SetFocus

Cancel = True ' should suffice

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top