Message box error check box

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

I have built a databse, on a form i have a close button i want to do
a few checks to see if certain text boxes have data in them. I would
want message box and then i want it to set focus to that box ( and
highty llight it in red if pos)

I have about 10 checks to do on every form that the best way to do
this
 
Simon said:
I have built a databse, on a form i have a close button i want to do
a few checks to see if certain text boxes have data in them. I would
want message box and then i want it to set focus to that box ( and
highty llight it in red if pos)

I have about 10 checks to do on every form that the best way to do
this

Add something like a "2" to the Tag property of the textboxes you want to
check. Try using the code below in a standard module:

Public Sub CheckIt(frm As Form)
'© Arvin Meyer 12/25/09
' Free use permitted if copyright left intact
On Error Resume Next

Dim ctl As Control

For Each ctl In frm.Controls
With ctl
If .ControlType = acTextBox Then
If ctl.Tag = 2 Then
MsgBox "Please fill in the required data", vbOKOnly,
"Data Required"
ctl.SetFocus
Exit Sub
End If
End If
End With
Next ctl

Set ctl = Nothing
Set frm = Nothing

End Sub

Call it like:

Private Sub Form_BeforeUpdate(Cancel As Integer)
CheckIt(Me)
End Sub
 
Back
Top