Why VBA with Me! cannot work ?

  • Thread starter Martin \(Martin Lee\)
  • Start date
M

Martin \(Martin Lee\)

The following can work
DoCmd.OpenForm "abccc", acNormal, acEdit
[Forms]![abccc]![Label750].Caption = "I love you"


But why the following VBA with "Me!" can't work?

DoCmd.OpenForm "abccc", acNormal, acEdit
Me![Label750].Caption = "I love you"



Thank you!
 
G

Guest

'Me' is in the code of a form and will therefore always point to the form to
which that code belongs.
 
G

Guest

Hi Martin

The reason the "me" will no work is that (I assume) you are using the
OnClick (or something else) event from a form to open another form and the
"me" will refer to a control on the 1st form form.
Don't use a lable to contain the text - use a text box.

Use this
Private Sub ButtonOn1stForm_Click()
DoCmd.OpenForm "2ndForm", acNormal, "", "", , acNormal
Exit Sub
Forms!2ndForm!TextBoxName = "I love you"
End Sub


--
Buon Natale, Happy Chritmas.

Wayne
Manchester, England.
Scusate,ma il mio Inglese fa schiffo :)
Percio se non ci siamo capiti, mi mandate un
messagio e provero di spiegarmi meglio.
 
J

JK

Martin,

As Wayne said Me! (or Me.) works on the *current* form, in or der to get it
to work the form must have the focus, this should work

DoCmd.OpenForm "abccc", acNormal
DoCmd.SelectObject acForm,"abcc" '***Setting the focus
Me![Label750].Caption = "I love you"

Regards
Jacob
 
D

Dirk Goldgar

JK said:
Martin,

As Wayne said Me! (or Me.) works on the *current* form, in or der to
get it to work the form must have the focus, this should work

DoCmd.OpenForm "abccc", acNormal
DoCmd.SelectObject acForm,"abcc" '***Setting the focus
Me![Label750].Caption = "I love you"

Sorry, Jacob, that won't work. "Me" doesn't necessarily refer to the
form that has the focus; rather, it refers to the class object
containing the running code. In the case of a form, that would be the
form containing the "Me" reference being resolved. So in code behind
FormX, "Me" always refers to FormX, while in code behind FormY, "Me"
always refers to FormY.
 
J

JK

Oops Dirk,

You are absolutely right, I was not thinking, sorry.

Regards
Jacob
(Who did not engage brain before hitting Send)

Dirk Goldgar said:
JK said:
Martin,

As Wayne said Me! (or Me.) works on the *current* form, in or der to
get it to work the form must have the focus, this should work

DoCmd.OpenForm "abccc", acNormal
DoCmd.SelectObject acForm,"abcc" '***Setting the focus
Me![Label750].Caption = "I love you"

Sorry, Jacob, that won't work. "Me" doesn't necessarily refer to the form
that has the focus; rather, it refers to the class object containing the
running code. In the case of a form, that would be the form containing
the "Me" reference being resolved. So in code behind FormX, "Me" always
refers to FormX, while in code behind FormY, "Me" always refers to FormY.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
M

Martin \(Martin Lee\)

I tried all of the method concerning Me! , can't work

Dirk Goldgar said:
JK said:
Martin,

As Wayne said Me! (or Me.) works on the *current* form, in or der to
get it to work the form must have the focus, this should work

DoCmd.OpenForm "abccc", acNormal
DoCmd.SelectObject acForm,"abcc" '***Setting the focus
Me![Label750].Caption = "I love you"

Sorry, Jacob, that won't work. "Me" doesn't necessarily refer to the form
that has the focus; rather, it refers to the class object containing the
running code. In the case of a form, that would be the form containing
the "Me" reference being resolved. So in code behind FormX, "Me" always
refers to FormX, while in code behind FormY, "Me" always refers to FormY.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
L

Larry Linson

I tried all of the method concerning Me! , can't work

You are doing _something_ wrong, Martin. "Me" definitely does work with
every version of Access, when used in the module directly associated with a
Form or Report (which is a class module, just for the record). It also works
in a user-created class module. I've used it almost every day since 1994.

It does NOT work in standard modules, nor expressions outside class
modules... chances are high that you are trying to use it in an
inappropriate circumstance.

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top