Link to home
Start Free TrialLog in
Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on

Invalid use of Me. keyword

Experts,
The following code is in a module I call modChangeVisiblty:

    Me.LineCode.Locked = False
    Me.ScrapTicketDate.Locked = False
    Me.ScrapTicketShiftNumber.Locked = False
    Me.LineCode.SetFocus
    Me.txtBOMDescribed.Visible = False
    Me.lblChargedTo.Visible = False
    Me.LineCodeID.Visible = False
End Sub

The code worked fine until I placed it is the module and called it

Call mChangeVisiblty and received the Invaalid use of M.e keyword error
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Me is a shorthand notation for a form.

You need to explicitly specify the form when you put this in generic module not associated with the form.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frank Freese

ASKER

cap,
got an error Compile error: Argument not optional at

Call mChangeVisibilty
cap, saw that error...correcting and still working on problem
changed to code in mChangeVisibilty and thought Compile eror would go away. still there, at Call mChangeVisibility

With Forms(sForm)
  .visible=True
  .lblChargedTo.visible=true
.
.
.
End With
End Sub
Check out the CodeContextObject, much easier as it referes to the object the code is running from.
Cheers, Andrew
change way you call the sub to include the name of the form


Call mChangeVisibilty(me.name)  

or

Call mChangeVisibilty("Form1")  'where Form1 is the Name of the form
ok folks....i think i found MY error.
Call changeVisibilty
should have been
Call changeVisibilty(sForm)
thanks for the information and allowing me the time to understand what i did wrong.
Being a little nitpicky... Me is a shorthand reference to the class a class module is bound to.  You often see it
used in Form or Report modules, which are really class modules.  If you create your own classes, the Me
keyword when used in those class modules would refer to the class defined in the module.

:)
matthewspatrick, agreed but explaining the quote below from the Access Help on ME  to most users is a waste of time.

"The Me keyword behaves like an implicitly declared variable. It is automatically available to every procedure in a class module. When a class can have more than one instance, Me provides a way to refer to the specific instance of the class where the code is executing. Using Me is particularly useful for passing information about the currently executing instance of a class to a procedure in another module. For example, suppose you have the following procedure in a module:"

Cheers, Andrew