Invalid use of Me

  • Thread starter Thread starter Joe Williams
  • Start date Start date
J

Joe Williams

I am trying to set up code that will change the properties of each form's
control when the form is loaded. I want this behavior to happen for every
form in my application, so I thhought I would be smart and make the code a
public function and put it in a module. That way each form only needs to
call the publiic function.

However, when I run the code I get an "'invalid us of me" error. I am
assuming it is becuase Access cannot reconcile the me reference at the
module level. how can I make the following code work so that I only have to
have one master function which will then look up the form name when it is
running and set the properties accordingly ? (versus using me.controls)....
Thanks

For Each ctrl In Me.Controls ' Loop through the controls on the form
If ctrl.Properties("Name") Like "lbl*" Then
ctrl.Properties("ForeColor") = LabelColor ' Set a Property value for the
control
Else
End If

Joe
 
Joe Williams said:
I am trying to set up code that will change the properties of each form's
control when the form is loaded. I want this behavior to happen for every form
in my application, so I thhought I would be smart and make the code a public
function and put it in a module. That way each form only needs to call the
publiic function.

However, when I run the code I get an "'invalid us of me" error. I am assuming
it is becuase Access cannot reconcile the me reference at the module level.
how can I make the following code work so that I only have to have one master
function which will then look up the form name when it is running and set the
properties accordingly ? (versus using me.controls).... Thanks

For Each ctrl In Me.Controls ' Loop through the controls on the form
If ctrl.Properties("Name") Like "lbl*" Then
ctrl.Properties("ForeColor") = LabelColor ' Set a Property value for the
control
Else
End If

Modify the code so it accepts a FormName argument. Then call it like...

YourFunction(Me.Name)
 
Joe said:
I am trying to set up code that will change the properties of each form's
control when the form is loaded. I want this behavior to happen for every
form in my application, so I thhought I would be smart and make the code a
public function and put it in a module. That way each form only needs to
call the publiic function.

However, when I run the code I get an "'invalid us of me" error. I am
assuming it is becuase Access cannot reconcile the me reference at the
module level. how can I make the following code work so that I only have to
have one master function which will then look up the form name when it is
running and set the properties accordingly ? (versus using me.controls)....
Thanks

For Each ctrl In Me.Controls ' Loop through the controls on the form
If ctrl.Properties("Name") Like "lbl*" Then
ctrl.Properties("ForeColor") = LabelColor ' Set a Property value for the
control
Else
End If


Add am argument for the form object to your procedure.

Public Sub SetFormProps(frm As Form)
For Each ctrl In frm.Controls
. . .

Then in each form's Load event, call the procedure this way:

SetFormProps Me
 
Back
Top