Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / July 2005

Tip: Looking for answers? Try searching our database.

Code to refer to the caption of a label bound to a control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kurt - 29 Jul 2005 18:13 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 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."
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.