Form Control Buttons

J

JudithJubilee

Hello there,

I am having major problems adding Control Buttons to my
forms. I was adding New Record, Next, Previous and Close
to all my forms. They were working when I set them but
now they are giving an error message each time:

"The expression On Click you entered as the event
property setting produced the following error:
Ambiguous name detected: cmdClose_Click."

I am not coding, just using the Wizard. I have been back
and deleted all my command buttons but even now when I
add another one I get the same results.
If anyone can help it would be muchly appreciated - I'm
tearing my hair out here!!!

Judith
 
J

Jeff Conrad

Hi Judith,

Please, no hair pulling; it's bad for the keyboard. <g>

This is a classic example of Access not cleaning up after
itself. When you delete command buttons from the form,
Access does not delete the underlying code attached to
that button. So if, for example, you create a button
called cmdClose_Click using the wizard and later delete it,
the code is still there in the form's module. If you then
create another button called cmdClose_Click you now have two
subroutines in the code with the same name. Access gets
confused because it sees two code routines (or more) for
the same button. It is the Access equivalent of "leaving the seat up."

Go look at the code module behind your form and carefully
look around. You will probably see two or more code
routines for cmdClose_Click. Delete the code that is not needed.
Then compile your code to see if there are any other problems.
That should take care of it.
 
J

JudithJubilee

Thankyou for your reply. I don't know too much about
code, but I've gone to each form chosen Code and deleted
all the code. It now appears to be working properly.

However, I think the problem arose from a "template" I
created.

I created a form with things like Record Selectors and
Navigation Buttons turned off. I also added 4 buttons
using the wizard: Next Record - cmdNext, Previous Record -
cmdPrevious, New Record - cmdAddNew and Close - cmdClose.

I then saved this as frmTemplate. To create all my forms
I then opened the frmTemplate and Saved As then added my
fields and moved the buttons around as appropriate.

Is that what caused Access to flip out??
If it is, what can I do rather than creating the new
buttons and changing my form properties every time??

You help is much appreciated!
Judith
 
J

Jeff Conrad

message
Hi Judith,

Comments below....
Thank you for your reply. I don't know too much about
code, but I've gone to each form chosen Code and deleted
all the code. It now appears to be working properly.

Good to hear it is working now.
One of the many things that makes Access such a powerful tool
is that it can be as simple or as complex as you need it to be.
It is possible to build simple databases with virtually no knowledge
of VBA. By just using the wizards you can make a fully functioning
database. This is actually how I started. Once you begin to understand
the VBA language, endless possibilities emerge.

I would like to make a suggestion if you do not mind. When you
use the wizard to make a command button, after it is finished go
look at the code window and see what it created. Don't worry
about completely understanding everything at this point, just
take a look at it. As time progresses, you will begin to see patterns
and it will start to make sense. It won't happen overnight, but
just keep at it. It is quite fun to see how things are working in
the background and then you will begin to "tinker" with coding
yourself. Ahhhh the power!
However, I think the problem arose from a "template" I created.
I created a form with things like Record Selectors and
Navigation Buttons turned off. I also added 4 buttons
using the wizard: Next Record - cmdNext, Previous Record -
cmdPrevious, New Record - cmdAddNew and Close - cmdClose.

Sounds fine.
I then saved this as frmTemplate. To create all my forms
I then opened the frmTemplate and Saved As then added my
fields and moved the buttons around as appropriate.

OK, I see.
You were using this form as a template base for building
"copy cat" forms. That is sometimes quite normal to do. You
can also right click on a closed form (or other objects) and select
"Copy" and then "Paste" a new one into the Database Window.

My personal taste is to have these "template" forms and reports
in an external database. They have all the basic layouts and controls
I would need on new forms and reports. It is a time saver to be sure.
Whenever I need another one I just import it by going to:
File | Get External Data | Import
I rename it once it is in my current database and then start working
away.

A major word of caution on this! Make sure you have all the
latest service packs and updates for your Access version. Access
2000 had a very nasty bug (fixed in SP3) that could corrupt
your database if you imported code-bearing objects and did
not compile before closing the database. Always keep your
system patched and up-to-date by going to Office Update on
Microsoft's site.
Is that what caused Access to flip out??

Just the creation of the new form, no.
If it is, what can I do rather than creating the new
buttons and changing my form properties every time??

Access became confused only because you deleted a command
button and then recreated another one with the same name.
Access does not remove any associated code for a control
on a form (or report) when you delete it. Many, including
myself, think this would be great if Access did this, but for
now Access does not have this capability. The "ambiguous"
error you received is just the default Access message
programmed in that handles the case when it cannot make
sense of a code routine because two or more exist with
the same name. The error would probably make more sense
to people if it said, "There are duplicate code routines for
xxxxx control."

So how do you avoid this?
Well, as I mentioned earlier, just open the code module once
in a while and take a look around., especially when you delete
and create command buttons. You may not understand everything,
but you should be able to spot duplicate entries pretty easily.
Also, try compiling your database after making some changes.
Here is how you do this:
1. Go to any code module (sounds like you already know how
to get there)
2. If you are using Access 97 go up to the menu bar and select:
Debug | Compile And Save All Modules
If you are using Access 2000, 2002, or 2003 then select:
Debug | Compile <name of your database>

What this does (in simple terms) is to tell Access to see if it
can find any coding problems. If you have duplicate coding
entries Access would have found it right away and probably
highlight the very problem it found! Very useful tool.
You help is much appreciated!

No problem, glad to help.

--
Jeff Conrad
Access Junkie
Bend, Oregon
 

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