Problem naming controls

A

atlinc

I built a simple form in Access 2K. It has a textbox, listbox and two
command buttons. I went to the properties window/other tab and named my
controls. I opened the Visual Basic editor and went to the drop down
list of controls and all of the controls were still named with the name
Access gave them when they were created. For example the first command
button I created was given the name Command4 and I named it cmdAdd but
in the VBE dropdown list it is still named Command4. This has happened
to me before and I believe I got it to recognize my names by going to
Debug/Compile, but it isn't working this time.

Can anyone tell me why this sometimes happens and sometimes not when I
create a form? And what can I do to get the VBE to recognize the names
I have assigned? BTW the control names I assigned are not the same as
the names of any fields in the database, nor are they reserved words.
 
A

Allen Browne

You are correct: when you rename a control, any code that was associated
with it becomes disassociated, and retains the old name.

The solution is to search'n'replace in the code window to change all
occurrences of that name in that module. (On the Edit menu.)

In general, you want to change the name of the control before you assign any
event procedures to it.

There are some contexts where Access attempts to still recognise a field
where you change its name, but it does not even attempt to do that in the
VBA code window. In any case, the implementation of this is so flawed that
it is much more likely to corrupt your database than much else. More
details:
Failures caused by Name Auto-Correct
at:
http://allenbrowne.com/bug-03.html

It sounds like you are probably aware of the problems that can result from
using reserved words as control names. If you are interested, tblBadWord
contains a list of those names to avoid in this utility database:
http://allenbrowne.com/AppIssueChecker.html

And just BTW, personally I don't bother changing the name of every control
so it is different from the name of the field it is bound to. My style is to
use the prefixes on unbound controls and controls bound to expressions only.
 
G

Guest

Hi,

I think no one has yet addressed your very first problem. After you have
typed a new control name in the properties box make sure you type a [TAB] or
[ENTER] to force an update before navigating to the next control. There are
situations where the UI fails to overwrite the control name.

Rod
 
A

atlinc

Thanks Rod, that was the problem. I would click on a control to select
it, go to the properties box and name it, click on the next control and
so on. This would change the name in the Access environment but not the
VB environment. Isn't that strange? Anyway, hitting [ENTER] before
moving on takes care of the problem. Thanks again for the help!

Rod said:
Hi,

I think no one has yet addressed your very first problem. After you have
typed a new control name in the properties box make sure you type a [TAB] or
[ENTER] to force an update before navigating to the next control. There are
situations where the UI fails to overwrite the control name.

Rod

I built a simple form in Access 2K. It has a textbox, listbox and two
command buttons. I went to the properties window/other tab and named my
controls. I opened the Visual Basic editor and went to the drop down
list of controls and all of the controls were still named with the name
Access gave them when they were created. For example the first command
button I created was given the name Command4 and I named it cmdAdd but
in the VBE dropdown list it is still named Command4. This has happened
to me before and I believe I got it to recognize my names by going to
Debug/Compile, but it isn't working this time.

Can anyone tell me why this sometimes happens and sometimes not when I
create a form? And what can I do to get the VBE to recognize the names
I have assigned? BTW the control names I assigned are not the same as
the names of any fields in the database, nor are they reserved words.
 

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