Re: Me. vs Me!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dirk Goldgar (dg_at_NOdataSPAMgnostics.com)
Date: 06/04/04


Date: Fri, 4 Jun 2004 17:06:50 -0400


"Derek Wittman" <anonymous@discussions.microsoft.com> wrote in message
news:AF58A59E-34D7-4FA2-A8F3-F639055A0BBA@microsoft.com
> Good morning,
> I know I saw something in the last few days on this topic, but I lost
> it. I continue to have to reference form controls like
> Forms!frmFORMNAME.controlname rather than (from form code)
> Me!controlname or Me.controlname.
>
> I did some hunting in the help files and they suggest that the Me! or
> Me. syntax may only be used in a class module (which I don't believe
> this qualifies as).
>
> Can someone please help me out?
> Thank you!
> Derek

Derek -

I looked through the earlier posts in this thread, and I'm not sure that
they made it clear that you can only use the "Me" keyword from VBA code
that is part of the form's (or report's) code module. That is, in code
"behind the form", you can use Me.controlname or Me!controlname to refer
to a control on that form, or Me.propertyname to refer to a property of
that form, but ...

    (a) you can't use "Me" to refer to a form other than the one the
code is running on, and

    (b) you can't use "Me" in a standard module; only in a class module
(a form or report's code module, or a user-defined class module), and

    (c) you can't use "Me" in a controlsource expression or in a query.

If you are concerned with two forms, "FormA" and "FormB", then in code
running behind FormA you can refer to control txtFieldOnA on FormA using
any of these:

    Me.txtFieldOnA
    Me!txtFieldOnA
    Forms!FormA!txtFieldOnA

(That last isn't as efficient as the others, though.) If there's a
control on *FormB* named txtFieldOnB, though, the only way you can refer
to it from code on FormA is

    Forms!FormB!txtFieldOnB

or one of several equivalent versions of that reference syntax. You
can't use "Me", though, because txtFieldOnB isn't on "me" (FormA); it's
on FormB.

Does that explanation help at all?

-- 
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)


Relevant Pages

  • Re: Me. vs Me!
    ... And, just so I don't have to keep wrestling with the pronoun ME, I tend to use full control names quite a bit, or set them to string variables. ... I continue to have to reference form controls like ... running behind FormA you can refer to control txtFieldOnA on FormA using ...
    (microsoft.public.access.modulesdaovba)
  • Re: Disable/Enable form controls from another form within the same DB.
    ... If FormA is open, you should be able to refer to a control on it as ... > I created this huge database for this task force at my agency. ...
    (microsoft.public.access.forms)
  • Re: PROBLEM: Keywords;= Userform, Class Modules, ButtonGroup and Nomenclature
    ... one can simply refer to a control created as a new collection in a ... Class Module *draws an error. ... Myles. ...
    (microsoft.public.excel.programming)
  • Re: Invalid identifier following null constant
    ... Not clear on what you mean by 'it is a class module for FormA'. ... If it's in another module you need to qualify the control name, ... Imran J Khan wrote: ...
    (microsoft.public.access.modulesdaovba)
  • Re: Adding controls at Runtime in Userforms?
    ... So internally the classes control ... >controls event handler class when you ... >as a pointer to a class module, you then try to use it ... >> Dim ButtonClass as clsCmdButton ...
    (microsoft.public.word.vba.general)