How to refer to a label's caption (1 Viewer)

flemmo

Registered User.
Local time
Today, 14:22
Joined
Apr 26, 2006
Messages
69
Hi,

I'm brand new to VB, but here goes :)

Could someone tell me the syntax to reference and change a label's caption?
Basically I want a little text box that to easy test that variables are being passed around correctly.

Just to further explain the structure, I have

Form > Label > Caption.

Thanks!
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:22
Joined
Jul 9, 2003
Messages
16,245
This code in VBA: Label13.Caption = "XXX"

will change the label named label13 to read "XXX"
 

flemmo

Registered User.
Local time
Today, 14:22
Joined
Apr 26, 2006
Messages
69
Cheers!
This works fine if the command and label are on the same form, but how could I reference the label in another form?

is it something like:

Form with Command Button onClick
formname.Labelx.Caption = "hello"

I tried this and it said 'Object Required'.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:22
Joined
Jul 9, 2003
Messages
16,245
Off the top of my head I think it's something like:


Forms_formname.Labelx.Caption = "hello"

But I need to check ................
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 14:22
Joined
Jul 9, 2003
Messages
16,245
You might find these posts helpful:

How to open a form at specific record?

Opening Form and Passing Variables

I thought I ought to explain the second example as at first glance it looks complicated however it is quite simple once you get the hang of it.

Code:
' This stores your form name as string 
       strDocName = "FormB" 

'if the form is not already open you will have to open it 
    DoCmd.OpenForm strDocName

'this is a "with block" it just saves you typing the name of the form every time.
With Forms(strDocName)
    .Caption = "Caption set from FormA" 'Form caption not a label!  
    .addrb1 = Me.Addr1
    .addrb2 = Me.Addr2
    .addrb3 = Me.Addr3
End With

"Addr1" data is extracted from this control on this form, and transferred to this control "addrb1" in the form you have opened, in this case "FormB"
 
Last edited:

flemmo

Registered User.
Local time
Today, 14:22
Joined
Apr 26, 2006
Messages
69
Yep, works perfectly using your method
Thanks very much :)
 

Users who are viewing this thread

Top Bottom