Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a control name as string 1

Status
Not open for further replies.

jpstroud

Technical User
Jun 18, 2004
93
US
Okay, I'm not sure why I'm having troubles with this, but I'll blame it on it being Friday :)

I'm attempting to pass the name of a control as a string to a subroutine elsewhere in the module. Unfortunately, I'm getting an "Object variable or With block variable not set" message when I try to run the code. I can't seem to track down why I'm getting the error. The sub's code is here:

Code:
Sub sub_ShowBalance(strControl As String)
    Dim ctlLabel As Control, ctlBalance As Control
    
    ctlBalance = Me(strControl)
    ctlLabel = Me(strControl & "_Label")
    
    With ctlBalance
        If .Value & "" = "" Then
            .Visible = False
            ctlLabel.Visible = False
        Else
            .Visible = True
            ctlLabel.Visible = True
        End If
    End With
End Sub

Any thoughts? Thanks!
 
Try instantiating them (set):

[tt] set ctlBalance = Me(strControl)
set ctlLabel = Me(strControl & "_Label")[/tt]

- note - if the label is attached to the control, you only need to address the control, the label will inherit the visible property.

Roy-Vidar
 
See, I knew it was simple. Friday got me again. Thanks!

And thanks for the extra note. I've never had a need to hide/unhide anything really, so I wasn't aware that the label inherited those properties.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top