I use controls’ tag property and BeforeUpdate code to validate missing data
on a form. How can I edit the MsgBox below to show the caption of the label
that’s bound to the control, instead the name of the control (ctl.Name)
that’s currently used? Thanks. - Kurt
###
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "*" Then
If IsNull(ctl) Or ctl = "" Then
MsgBox "You must complete the required field '" & " " &
ctl.Name & " " & "' before you can continue.", vbCritical, "Required Field"
ctl.SetFocus
Cancel = True
Exit Sub
End If
End If
Next
Set ctl = Nothing
End Sub
Dirk Goldgar - 29 Jul 2005 18:37 GMT
> I use controls' tag property and BeforeUpdate code to validate
> missing data on a form. How can I edit the MsgBox below to show the
[quoted text clipped - 22 lines]
>
> End Sub
Dim strFieldName As String
' ...
If ctl.Controls.Count > 0 Then
strFieldName = ctl.Controls(0).Caption
Else
strFieldName = ctl.Name
End If
MsgBox "You must complete the required field '" & _
& strFieldName & "' before you can continue."

Signature
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
Kurt - 29 Jul 2005 19:19 GMT
Works great. Thanks.
> > I use controls' tag property and BeforeUpdate code to validate
> > missing data on a form. How can I edit the MsgBox below to show the
[quoted text clipped - 35 lines]
> MsgBox "You must complete the required field '" & _
> & strFieldName & "' before you can continue."