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

Why won't my validation run?

Status
Not open for further replies.

newbyvba

Technical User
Feb 22, 2012
11
I've put a * in the fields that I want filled in. I've put this code and nothing validates... any ideas? its like there's no validation on there at all!!

Private Sub Form_BeforeUpdate(Cancel As Integer)
' check field for * in tag and check if text entered and provide error
Dim Msg As String, Style As Integer, Title As String
Dim DL As String, ctl As Control

DL = vbNewLine & vbNewLine

For Each ctl In Me.Controls
If ctl.Tag = "*" Then
If ctl.Value = Null Or ctl.Value = "" Then
Msg = "'" & ctl.Name & "' is required and can't " & _
"be left blank!" & DL & _
"please go back and enter some data! . . ."
Style = vbInformation + vbOKOnly
Title = "Missing Required Data Error! . . ."
MsgBox Msg, Style, Title
Cancel = True
ctl.SetFocus
Exit For
End If
End If
Next

End Sub
 

Just a guess here.
Perhaps because the asterisk is used as a wild card character?
Have you tried a different character in the ctl.Tag?


Randy
 
I've just tried an L instead but it still didn't do anything :-( its so frustrating!
 
The following line is always false
Code:
 If ctl.Value = Null
if isnull(ctl.value)

null = null return null not true
 
Replace this:
If ctl.Value = Null Or ctl.Value = "" Then
with this:
If Trim(ctl.Value & "") = "" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

Have you verified that the BeforeUpdate event is firing?

Is your form bound or unbound? (Unbound forms do not fire the Before or After Update Events.)

In Access97 you have to make sure the 'On BeforeUpdate' property is set to [Event Procedure] (later versions do a better job of taking care of that for you.)

Put a message box or a debug.print in the event code to ensure the event is firing. If it is, put a break in to check the properties of the controls as they go through the loop.

Then let us know what you find.
 
I've replace the If ctl.value = null with the isnull(ctl.value) and brilliant, it works - thank you. HOwever, after the message box displays, immediately afterwards displays an error: Runtime error 3021 No current record. Is there a way to stop this happending please?
Thanks you for all your help
 
something like?

Code:
On Error Resume Next

If Err.Number = 3021 Then
'do something
Err.Clear ' clear the error when were done handling it
Else
'goto our error handler another error type has occured
End if

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top