Renaming control breaks module ?

G

GeorgeAtkins

Access 2007.
Help! I create a form in a 2007 database. Add a command button (no wizard)
and attach some code to its click event. I have not changed the name of the
cmd button yet. The code works on click. it seems that if I rename the button
(moving the code to the new click event created in VBE) and try to use it,
suddenly it doesn't work and neither do any other buttons on the form.

When I click on a button, the following error appears:
"The expression On Click you entered as the event property setting produce
the following error: user-defined type not defined"

It doesn't matter if I delete the button and start it from scratch, no
button ever works on that form again. In addition, when in VBE, when I want
to add some code tor reference the form, the "me." option fails to elicity a
property list. In fact, the property window does not automatically fill-in,
either. I've repeated this in different databases, even new ones. I'm sure it
must have somethig to do with renaming command buttons, but I just can't
figure out what's going wrong. It's as if the module becomes completely
unconnected. The additional notes on the error point out: "This error occurs
when an event has failed to run because Microsoft Office Access cannot
evaluate the location of the logic for the event. " which tends to support my
theory. I did run the Diagnostics and it found nothing out of order.
How can I fix this and prevent it from recurring? Thanks for any help.
 
A

Allen Browne

This seems like the kind of problem that a decompile might fix.

Try a sequence like this:
1. Uncheck the boxes under:
Office Button | Access Options | Current Database | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

2. Compact the database to get rid of this junk:
Office Button | Manage | Compact/Repair

3. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

4. Open Access (holding down the Shift key if you have any startup code),
and compact again.

5. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html

6. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.
 

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