How to use a function in a module

padlocked17

Registered User.
Local time
Today, 08:26
Joined
Aug 29, 2007
Messages
275
Good Evening,

I have a snippet of code that I want to be able to call up on multiple forms so I was going to place it in a module. I've got the following and I'm not sure what to replace the "Me." with since it's throwing an error:

Code:
Sub switchOnOff(onoff As Boolean)

    Me.TabCtl1.Visible = onoff
    Me.Label12.Visible = onoff
    Me.Label13.Visible = onoff
    Me.Label14.Visible = onoff
    Me.Label20.Visible = onoff
    Me.FirstName.Visible = onoff
    Me.MI.Visible = onoff
    Me.LastName.Visible = onoff
    Me.Type.Visible = onoff

End Sub
 
Russ,

As a subroutine or function in a Public module, it won't be able to see
your form. Therefore it has no concept of "Me.".

You can alleviate that by passing the form as a parameter to the sub/function
but that means that it isn't "reusable" because of all of the references like:

Me.Label13.Visible = onoff

To make the routine Public you sacrifice all knowledge of the form's local
controls. Surely they're not all called Label13, etc.

Wayne
 
The Me. scoping predicate has no meaning in a standard module, hense the error. This code seems to be unique to a particular form so why not just put the SubRoutine in that form's class module?
 

Users who are viewing this thread

Back
Top Bottom