Why Can't code /event procedure see a renamed field?

F

FredFred

I'm old to Access and new to access programming.

An event procedure never seems to recognize the new names of renamed fields.
In fact, it does recognize and access renamed fields by their previous
names.

Is this an Access bug or a newbie arror?
 
G

George Nicholson

Code won't update itself.

If you change the name of anything (controls, fields, queries, reports,
forms, variables, etc.) you also need to manually change any references to
those names in code, even in "attached" Event procedures.


The only thing I can think of that will automatically update in code is
capitalization within a variable name. If you change

Dim strmyvar
to
Dim strMyVar
(exact same spelling, different capitalization)
any existing references to strmyvar in your code will change to strMyVar.

Nice, but of limited usefulness :)

But Find & Replace is available in the VBE...

HTH,
 
B

bob

Look at this: Tools | Options| General| Perform Name Autocorrect

You probably should de-select Perform Name Autocorrect...leaving it on
causes some strasnge things to happen when you change names

Bob
 
F

FredFred

Thanks, but that's not what I meant, my problems is actually the reverse.
Sorry for the ambiguous wording.

If, in the table, I change a field name from "FieldA" to "FieldB", the code
errors out if I call FieldB. But it accesses the field if I use the OLD /
gone name "FieldA".
 
F

FredFred

Thanks, but that's not what I meant, my problems is actually the reverse.
Sorry for the ambiguous wording.

If, in the table, I change a field name from "FieldA" to "FieldB", the code
errors out if I call FieldB. But it accesses the field if I use the OLD /
gone name "FieldA".
 
F

FredFred

Thanks, I'll try that.



bob said:
Look at this: Tools | Options| General| Perform Name Autocorrect

You probably should de-select Perform Name Autocorrect...leaving it on
causes some strasnge things to happen when you change names

Bob
 
A

Albert D. Kallal

FredFred said:
Thanks, but that's not what I meant, my problems is actually the reverse.
Sorry for the ambiguous wording.

If, in the table, I change a field name from "FieldA" to "FieldB", the
code
errors out if I call FieldB. But it accesses the field if I use the OLD
/
gone name "FieldA".

That is not correct and normal behavior of ms-access.


I suspect you being confused by the name of control on a form that *often*
has the SAME name as a underlying field, but they don't have to. In fact,
many a developers NEVER name controls on the screen the same as the fields
to remove the confusing here.

You have to post the one line of code, but if your actually reference the
field, and not a control, then if you change the name, the your code needs
to be changed....

You have to post the one line of code that "seems" to be working correct
with the "old" field name. I suspect the code is not actually referencing a
old field name..but a control on a form.

Note that a form DOES create references to field names, and you can
generally use the "dot" notation, but if you change the forms record source
at a runtime, or rename fields...then those references are not always
updated. (unless you go into the form, change the data source, and change it
back).

As a result of the above, you generally should use:


1) to reference a forms underlying data, use bang notation

me!NameOf field, or for a full form ref, use
forms!NameOfForm!NameOfDataField

2) to reference a control on a form, use dot notation
regardless of the
underlying data or even a un-bound form, use
me.nameOfcontorl, or for a full form ref, use
forms!NameOfForm.NameOfContorl

So, if you had been using bang notation to reference the underlying data in
the first palce, changing the field name will force you to change your
code...
 

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