Function to hide a control = object missing?

rudeboymcc

Registered User.
Local time
Today, 04:51
Joined
Sep 9, 2008
Messages
69
Hi. I've got a form which is very similar apart from a few texts boxes, so I hide the relevant textboxes that I don't need dpending on the OpenArgs.

E.g.
Code:
  Me.cmbHB.Visible = True
        Me.cmbHB.Height = 0

I want to make a function like this:
Code:
Private Function HideControl(ctr As Control)
     ctr.Visible = False   
     ctr.Height = 0
End Function
But at the moment, If I call it with either of the two below in the Form Load event, it says "Object Required" and highlights the line (So it doesn't even get to the hideControl function)

Code:
HideControl(Me.cmbHB)
HideControl(Me.Controls("cmbHb"))

This is really simple but sometimes it's the simpelst things that take longest.
 
its possibly the brackets

try either

CALL HideControl(Me.cmbHB)

or just

HideControl Me.cmbHB
 
This will work
Code:
Private Sub Form_Load()
Dim cntName As String
cntName = "cmbHB"
    HideControl (cntName)
End Sub

Private Function HideControl(ctr As String)
     Dim ctrReceived As Control
     Set ctrReceived = Me.Controls(ctr)
     ctrReceived.Visible = False
     ctrReceived.Height = 0
End Function
 

Users who are viewing this thread

Back
Top Bottom