Change All Label Captions within a Form

Hi,

I like to update label Captions here within a form.

However I am only able to get the control Name and not the caption of that control.

The reason I like to update all Labels in a Form as I have always something like Cont_FirstName and so on..

I like to get rid of the "Cont_" so the caption is "Firstname"

Code:
Sub Test()
    Dim ctl As Access.Control
    Dim strOld As String
 
    strOld = "Cont_"
    Dim strNew As String
 
    strNew = ""
 
    For Each ctl In Forms!frm_Contacts  ' must be open in design view
        If ctl.ControlType = acLabel Then
            Debug.Print ctl.Name
         
            Dim strLabel As String
            strLabel = ctl.Name
            dislyke.com/instagram-captions/
            Debug.Print me.(ctl.Name).Caption)      'How To get this Property when not knowing the Control Name
         

        End If
    Next ctl
End Sub

Once I am able to receiving the Caption I am able to update that Label so I was hoping someone could help please.

Would be just nice as there are many Forms and Controls so it would be a nice thing to have.

Many thanks
After you change the caption of your label, use the Refresh-method of the
label to get it to repaint itself. Only then it shows its new value.
When you do not refresh the label, it is refresh when your code has
completed. As only then the events are handled by the system. So you could
use the ‘Do Events’ command, but it is much beter to just refrehs the label.

For more data search in MSDN for ‘Refresh’. It also gives you an example.
 
After you change the caption of your label, use the Refresh-method of the
label to get it to repaint itself.
That is not correct. Refresh is to do with the underlying data, not captions. It also happens automatically - typically 60 seconds as the default set in Options>client settings and is really only relevant in a multi user environment as it reflects changes in the current recordset made by other users.

Refresh differs from requery in that it looks at changes to the current records whereas requery will reapply any criteria and may add or remove records accordingly.
 
Ok I am changing slowly lol

Getting alot of not that great feetback of using prefixes and so I did in new application get rid of it :-)

Cheers
 
Hi Doc_Man,

thanks for your input too.

I am a little lost with what you mean exactly.

Also with CJ_London I do have a little difficulty to understand how to set it up correctly.
As mentioned it is a bit akward how I do it or done it.

Cheers

Sorry I'm a little late in replying.

What I meant was that if you did a "for each ctl in forms.controls" type of loop, you would know which control was associated with a label because the .Parent of a label is the control that owns it, whereas the .Parent of some other control is usually the form itself. I can't be certain, but I think most cases of controls are such that they have either a caption or a value but not both. The option group & option button get a bit complex about this, but most other controls do follow that general rule of having one or the other but not both. Controls also exist that have neither a .Value nor a .Caption - e.g. rectangles or lines. So that "for each" loop would do best to verify the control type of the control it was seeing at the moment anyway.
 
Hi Doc_Man

all good, I sometimes oversee it to and then I reply way to late so no problem at all!

But thanks for taking it on again and explaining it a little better, well explaining it so I understand it :-)

Very much appreciated!

Cheers
 

Users who are viewing this thread

Back
Top Bottom