Help referring to to object (in a module)

homer2002

Registered User.
Local time
Today, 07:21
Joined
Aug 27, 2002
Messages
152
Hi all


I have a sub that I cant get the syntax right on.

I am trying to get this to execute from a module
but I am having trouble referencing the object on the form
the sub should be called like this

call an(me,lblMyLabel,False) '(to hidethe label)
call an(me,lblMyLabel,False) '(to show the label)
___________________________________________

Sub an(formname As Form, myObject As Object, switch As Boolean)
formname![myObject].Visible = switch
End Sub

___________________________________________

(this isnt the whole sub obviously, just trying to keep things simple)

can anyone offer any enlightenment?
 
homer2002 said:
call an(me,lblMyLabel,False) '(to hidethe label)
call an(me,lblMyLabel,False) '(to show the label)
___________________________________________

Sub an(formname As Form, myObject As Object, switch As Boolean)
formname![myObject].Visible = switch
End Sub

Two things:

Firstly, the two calls you make are identical. One won't work unless the boolean you send is True.

Second thing:

Code:
Sub an(formname As Form, myObject As Object, switch As Boolean)
formname![myObject].Visible = switch
End Sub

A few things. When you send Me as a parameter you get the actual form, not its name. Me.Name produces the form's name property.

myObject is implicit. You can be more explicit by passing the parameter as a Label.

Change the lines to this:

Code:
Call an(Me.Name, Me.lblMyLabel.Name, False) ' (to hide the label)
Call an(Me.Name, Me.lblMyLabel.Name, True) ' (to show the label)

Code:
Public Sub an(strForm As String, strLabel As String, boo As Boolean)
    Forms(strForm).Controls(strLabel).Visible = boo
End Sub
 
Cheers mile, much appreciated,
look out for my next post (inspired by ghudson)
 

Users who are viewing this thread

Back
Top Bottom