Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44

    Unanswered: Need to see control's description not name in msgbox

    Hi all,

    I am struggling to display the form control description rather than the name in a message box. I would like to display the label name i.e description not the actual control name

    e.g House Number not address1

    Code:
    Dim Msg As String, Style As Integer, Title As String
       Dim ctl As Control, DL As String
       
       DL = vbNewLine & vbNewLine
       
       For Each ctl In Me.Controls
          If ctl.Tag = "?" Then
             If Trim(ctl & "") = "" Then
                Msg = "Required field '" & ctl.Properties("Name") & "' is Missing Data!" & DL & _
                      "You'll have to go back and correct this . . ."
                Style = vbCritical + vbOKOnly
                Title = "Required Data Error! . . ."
                MsgBox Msg, Style, Title
                
                Me(ctl.Name).SetFocus 'set focus to the field in error.
                Cancel = True         'cancel saving the record!
                Exit Sub              'return to the form for correction.
             End If
          End If
       Next
    Thanks in advance

    p.s i have tried ctl.Properties("Description") and ctl.Properties("Caption") to no avail

    All controls on form are text boxes and the forms record source is a table

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    either you want to examine the control source if you are using bound forms

    another technique is to stuff the description into the tag property and use use that
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44
    Thanks for the suggestion.

    I don't really want to be changing the controls at this late stage as this is a working form.

    I have considered using the Tag option but as you can see from the code i am already using this property as a qualifier to select the controls.

    Would it be possible to use the tag with for example (? control name) then in the code trim off the ? to just display the name?

    I know presume it would use the "right" function but i am not sure how the code would look.

    Any suggestions would be completely welcome

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    It sounds like you want the Caption of the label associated with the textbox or combo box. If so do you have a naming convention for your controls:

    txtAddress
    lblAddress

    If so, you can get the name of the control and create the name of the label and then display the Caption property of the label.

  5. #5
    Join Date
    Nov 2009
    Location
    UK
    Posts
    44
    sorry for the delay, i have now resolved by using the tag option and put the name in there.

    Thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •