which form event to update label name?

GBalcom

Much to learn!
Local time
Today, 11:13
Joined
Jun 7, 2012
Messages
460
Hi, I'm trying to change the name of the label in a form, upon opening the form in VBA...Does anyone know which form event I should use for this?

Thanks,
Gary
 
Do you mean the Label Name of the Label Caption?

The Caption you can change in the On Open Event of the form:

Me.mylabel.caption = "whateveryouwant"
 
Hi Catalina,
I'm looking to create some more efficient code of the following:

Code:
Private Sub Form_Loadtest()

Me.lblck1.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 1")
Me.lblck2.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 2")
Me.lblck3.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 3")
Me.lblck4.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 4")
Me.lblck5.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 5")
Me.lblck6.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 6")
Me.lblck7.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 7")
Me.lblck8.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 8")
Me.lblck9.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 9")
Me.lblck10.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 10")
Me.lblck11.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 11")
Me.lblck12.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 12")
Me.lblck13.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 13")
If IsNull(DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 14")) Then
    Me.lblck14.Visible = False
    Me.ck14.Visible = False
    
Else
Me.lblck14.Caption = DLookup("NameOnPrints", "tblTempPrintOptions", "Order = 14")
End If

Basically, I want check the condition of each checkbox control against a table. If the name is listed, I want to display it in the label. If it is not listed, I want to set the visibility of both the label and checkbox to false....I was trying a For Each Loop, but I'm stuck on how to accomplish...

Code:
Dim ctrl As Control
Dim frm As Form
Set frm = Forms!frmPrint
Dim OrderNum As Integer
OrderNum = 1
Dim strLabelName As String


For Each ctrl In frm.Controls
    'set names
        strLabelName = "lblck" & OrderNum
        
    If ctrl.Name = acCheckBox Then
        ''Debug.Print ctrl.Name
        If IsNull(DLookup("NameOnPrints", "tblTempPrintOptions", "Order = " & OrderNum)) Then
            ctrl.Visible = False
            
           '======THIS IS WHERE I'M STUCK
            Me.strLabelName.Visible = False
        End If
        
    End If
Next
 

Users who are viewing this thread

Back
Top Bottom