me.[controlname] problem

D

Darhl Thomason

I am creating an email to send to franchise owners as their store gets close
to construction starting. This code worked at one time, and I'm not sure
what I did to make it not work. I click a cmdButton the fires the onclick
event. Inside the onclick event it calls another sub to create the text of
the email (code snippet below). The problem is with the 2nd incidence of
me.[controlname]. When I click on the cmdButton, I get this error with
Me.txtCity highlighted as the problem "Compile Error/Method or data member
not found". So as part of my troubleshooting, I just pulled that from my
code and when I did, I got the same error with Me.txtOpenDate being the
highlighted code.

So, the first question is why is this failing? I have double-checked and
made sure this control does indeed exist on my form. The second question is
why does the second incidence fail but the first passes, then when I pull
out the second incidence, the first fails.

Thanks as always for any advice.

Darhl



strMsg = "Our construction schedule has your store opening on " &
Me.txtOpenDate & " " & _
"with POS installation occurring about 1 week prior. This puts
your upcoming store in " & _
Me.txtCity & ", " & Left(Me.txtNumber, 2) & " in the time frame
for POS installation."
 
D

Dirk Goldgar

Darhl Thomason said:
I am creating an email to send to franchise owners as their store
gets close to construction starting. This code worked at one time,
and I'm not sure what I did to make it not work. I click a cmdButton
the fires the onclick event. Inside the onclick event it calls
another sub to create the text of the email (code snippet below).
The problem is with the 2nd incidence of me.[controlname]. When I
click on the cmdButton, I get this error with Me.txtCity highlighted
as the problem "Compile Error/Method or data member not found". So
as part of my troubleshooting, I just pulled that from my code and
when I did, I got the same error with Me.txtOpenDate being the
highlighted code.

So, the first question is why is this failing? I have double-checked
and made sure this control does indeed exist on my form. The second
question is why does the second incidence fail but the first passes,
then when I pull out the second incidence, the first fails.

Thanks as always for any advice.

Darhl



strMsg = "Our construction schedule has your store opening on " &
Me.txtOpenDate & " " & _
"with POS installation occurring about 1 week prior. This
puts your upcoming store in " & _
Me.txtCity & ", " & Left(Me.txtNumber, 2) & " in the time
frame for POS installation."

You say your command button's Click event procedure calls another sub,
and it's that second sub that contains the code you posted. Is that sub
defined in the module of the form itself, or is the sub actually in a
different module? If it's in a different module, the references to
Me.<controlname> aren't going to work, because "Me" won't refer to the
form.
 
D

Darhl Thomason

Thanks for replying Dirk,

All of my code is contained within the form's module. I'm not 100% sure
when you say module because I know there is a place in Access for "modules",
but in this case all of the code is within the same place. I put the form
into design view then hit view/code and it lists all of the code. I'm
assuming this is what you mean by the form's module.

Thanks again,

Darhl


Dirk Goldgar said:
Darhl Thomason said:
I am creating an email to send to franchise owners as their store
gets close to construction starting. This code worked at one time,
and I'm not sure what I did to make it not work. I click a cmdButton
the fires the onclick event. Inside the onclick event it calls
another sub to create the text of the email (code snippet below).
The problem is with the 2nd incidence of me.[controlname]. When I
click on the cmdButton, I get this error with Me.txtCity highlighted
as the problem "Compile Error/Method or data member not found". So
as part of my troubleshooting, I just pulled that from my code and
when I did, I got the same error with Me.txtOpenDate being the
highlighted code.

So, the first question is why is this failing? I have double-checked
and made sure this control does indeed exist on my form. The second
question is why does the second incidence fail but the first passes,
then when I pull out the second incidence, the first fails.

Thanks as always for any advice.

Darhl



strMsg = "Our construction schedule has your store opening on " &
Me.txtOpenDate & " " & _
"with POS installation occurring about 1 week prior. This
puts your upcoming store in " & _
Me.txtCity & ", " & Left(Me.txtNumber, 2) & " in the time
frame for POS installation."

You say your command button's Click event procedure calls another sub,
and it's that second sub that contains the code you posted. Is that sub
defined in the module of the form itself, or is the sub actually in a
different module? If it's in a different module, the references to
Me.<controlname> aren't going to work, because "Me" won't refer to the
form.

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

(please reply to the newsgroup)
 
D

Dirk Goldgar

Darhl Thomason said:
Thanks for replying Dirk,

All of my code is contained within the form's module. I'm not 100%
sure when you say module because I know there is a place in Access
for "modules", but in this case all of the code is within the same
place. I put the form into design view then hit view/code and it
lists all of the code. I'm assuming this is what you mean by the
form's module.

Yes, that's the form's module. I'm puzzled by what you report, then.
Are you *sure* these controls are on the form, with the names you gave?
What happens if you change the "dot" to a "bang"; that is, instead of

Me.<control name>

write

Me!<control name>

? Does that make any difference?
 
D

Darhl Thomason

Dirk,

When I changed the dots to bangs, it started working fine. What's the
difference between using a dot and using a bang?

Thanks,

Darhl
 
D

Dirk Goldgar

Darhl Thomason said:
When I changed the dots to bangs, it started working fine. What's the
difference between using a dot and using a bang?

The dot signifies that the name that follows it is a property or method
of the preceding object, while the bang signifies that the following
name is a member of a collection owned by the object. In the case of an
Access form, the default collection is the form's Controls collection,
which contains all the controls on the form.

In practice, you can usually use the two notations interchangeably,
because Access makes both the fields in the form's recordset and the
controls on the form available as properties of the form -- if a control
has the same name as a field, the two are represented by a single object
that combines the properties of both the field and the control. This is
handy, because the dot notation makes it possible to use the
"intellisense" of the VBA editor, as well as providing compile-time
validation of your code.

But there are cases where this merging of controls and properties breaks
down. If either the field or the control has a name that is the same as
an existing property, it can't be made available as a property, so only
the bang notation can be used to refer to it. For example, if you have
a control or field named "Name", you can't refer to it using "Me.Name",
because that will always return the name of the form -- the value of its
Name property.

I don't see where the names you gave your controls would cause this kind
of confusion, though. that's why I'm puzzled. Unless ... do you have
the Name Autocorrect option turned on, and did you rename these controls
at some point, or rename something else that used the same names? Maybe
this is the result of Name Autocorrect making a mistake. You could try
turning the option off to see if that fixes the problem.
 

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