Can't get "Me" to work

  • Thread starter Thread starter el zorro
  • Start date Start date
E

el zorro

I'm trying to optimize my VBA by refering to a form field
using "Me" and the field name instead of including the
path beginning with "Forms," but I can't seem to get it
to work. (The form is opened from another form, from
which the user has selected a doctor. The new form opens
to the appropriate doctor) Here's part of the code I have
in the click event that opens the new form:

stLinkCriteria = "[nDoc]=" & Me![nDoctor]

'Open form to selected doctor
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Don't allow user to change name of facility
Forms!DoctorsF!DocFacility.Locked = True

THis works fine. But when I try to change that last line
to something like this:
Me!DocFacility.Locked = True, or Me.DocFacility.Locked =
True, it doesn't work. ANy idea where I'm going wrong?
THanks!
 
Yes, that's because you're focus is still on the calling form!
You'll have to use what you have or put the 'Me' command in the form itself.
 
el zorro said:
I'm trying to optimize my VBA by refering to a form field
using "Me" and the field name instead of including the
path beginning with "Forms," but I can't seem to get it
to work. (The form is opened from another form, from
which the user has selected a doctor. The new form opens
to the appropriate doctor) Here's part of the code I have
in the click event that opens the new form:

stLinkCriteria = "[nDoc]=" & Me![nDoctor]

'Open form to selected doctor
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Don't allow user to change name of facility
Forms!DoctorsF!DocFacility.Locked = True

THis works fine. But when I try to change that last line
to something like this:
Me!DocFacility.Locked = True, or Me.DocFacility.Locked =
True, it doesn't work. ANy idea where I'm going wrong?
THanks!

Is "DoctorsF" the name of the form containing the code, or the name of
the form the code just opened? "Me" refers to the object containing the
executing code, so
Me!DocFacility.Locked = True

will only work if DocFacility is a control on the form where this line
of code is being executed. I can't say for sure, but it looks to me as
though DoctorsF is the name of the form you're opening, not the name of
the form where this code resides.
 
Right-- DotorsF is the form being opened by the code.
THanks for pointing out why it won't work. (I was
thinking that once the form was opened, "Me" would refer
to that form, not the form with the code. Now I get it--
Me refers to the form with the code!)
-----Original Message-----
I'm trying to optimize my VBA by refering to a form field
using "Me" and the field name instead of including the
path beginning with "Forms," but I can't seem to get it
to work. (The form is opened from another form, from
which the user has selected a doctor. The new form opens
to the appropriate doctor) Here's part of the code I have
in the click event that opens the new form:

stLinkCriteria = "[nDoc]=" & Me![nDoctor]

'Open form to selected doctor
DoCmd.OpenForm stDocName, , , stLinkCriteria
'Don't allow user to change name of facility
Forms!DoctorsF!DocFacility.Locked = True

THis works fine. But when I try to change that last line
to something like this:
Me!DocFacility.Locked = True, or Me.DocFacility.Locked =
True, it doesn't work. ANy idea where I'm going wrong?
THanks!

Is "DoctorsF" the name of the form containing the code, or the name of
the form the code just opened? "Me" refers to the object containing the
executing code, so
Me!DocFacility.Locked = True

will only work if DocFacility is a control on the form where this line
of code is being executed. I can't say for sure, but it looks to me as
though DoctorsF is the name of the form you're opening, not the name of
the form where this code resides.

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

(please reply to the newsgroup)


.
 
Back
Top