VBA Command Buttons not working (1 Viewer)

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
Hello All.

I work in a hospital and have been working on a .mdb/.mde using Microsoft Office 2010. We are eventually upgrading to Office 365, which means I have to upgrade the database to a .accdb/.accde. To do so, I created a blank database and imported over all objects in to a new .accdb. Since doing so, none of the command buttons work in the database. When I click any command button, nothing at all happens.

When I create a new command button, I get the following message:

1635425706386.png



After the message appears, it does create a new command button. If I copy in the VBA code from any command button in to the code builder, nothing happens. However if I use the macro builder to do a simple open form, it works OK.

Any ideas as to why this may happen?

Below are my references:

1635425932354.png


Thanks in advance for your help.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:08
Joined
May 7, 2009
Messages
19,233
on the "new" button, can you select Code Builder, when adding code
then paste the code from the .mdb button?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:08
Joined
Aug 30, 2003
Messages
36,124
See if this helps, the database should be in a trusted location.

 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:08
Joined
May 7, 2009
Messages
19,233
are you sure the Original mdb was in created in A2010 or you are just opening it in A2010 before?
coz i just downloaded an mdb created in A2010 and the
conversion went without problem.
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
are you sure the Original mdb was in created in A2010 or you are just opening it in A2010 before?
coz i just downloaded an mdb created in A2010 and the
conversion went without problem.

Hi Arnel,

I copied the code from the .mdb on to the new button and nothing happens when it is clicked.

The mdb was likely created in Access 2003 or earlier. At some point I think the .mdb may have been imported in to an access 2010 .accdb blank database and then saved as a 2003 compatible .mdb.

Thanks
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
See if this helps, the database should be in a trusted location.


Hi,

Please see below what the trusted locations settings are set to:

1635427717077.png


The option to add a new trusted location is greyed out.

Thanks
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:08
Joined
Aug 30, 2003
Messages
36,124
You're definitely missing the wizard location plus of course the location of the db. Is there an "Enable Code" button in a bar below the ribbon?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:08
Joined
May 21, 2018
Messages
8,525
To do so, I created a blank database and imported over all objects in to a new .accdb. Since doing so, none of the command buttons work in the database. When I click any command button, nothing at all happens.
In design view when you look at the .onclick property of the buttons do you see "[Event Procedure]"? If this is blank you need to add it back in. You can do this by pasting it in, pulling down the dropdown, or click on the ellipsis.
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
You're definitely missing the wizard location plus of course the location of the db. Is there an "Enable Code" button in a bar below the ribbon?

There is nothing showing beneath the ribbon unfortunately.
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
In design view when you look at the .onclick property of the buttons do you see "[Event Procedure]"? If this is blank you need to add it back in. You can do this by pasting it in, pulling down the dropdown, or click on the ellipsis.

Please see below:

1635428685959.png


All of the code is there when I click on the 3 dots to go to the VBA screen
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:08
Joined
May 21, 2018
Messages
8,525
All of the code is there when I click on the 3 dots to go to the VBA screen
That was not the question. The question was if the word "[Event Procedure]" was already there? Or did it appear after clicking the ellipsis?
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
That was not the question. The question was if the word "[Event Procedure]" was already there? Or did it appear after clicking the ellipsis?
Sorry Maj, yes the Event Procedure was already there.
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
Update:

So I had previously imported the .mdb in to a new blank database in Access 2010. However I never put this in to use. I have imported this .accdb in to the new version of 365, and the command buttons are now working OK.

The references and trusted location are still the same, so I'm not certain what was causing the problem.

I am going to import the most recent .mdb in to access 2010, saved as a .accdb, and then import this in to Office 365. Hopefully this will all go well
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:08
Joined
May 21, 2018
Messages
8,525
Sorry Maj, yes the Event Procedure was already there.
The reason I asked this question (although no longer relevant) is that you can have event procedures in a form (such as a button_click), but if the event "onclick" property does not have "[event procedure]" there is no contract between the procedure and the event that caused it. The actual click action will not cause an event to be raised and thus the procedure has nothing to trap.

This can happen when you copy and paste code from one form to another. You will see the event procedure in the form, but the Event itself is not registered. I do think this is fixed in A 2016. I noticed if I paste code in the form the events are registered with "[Event Procedure]"
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
The reason I asked this question (although no longer relevant) is that you can have event procedures in a form (such as a button_click), but if the event "onclick" property does not have "[event procedure]" there is no contract between the procedure and the event that caused it. The actual click action will not cause an event to be raised and thus the procedure has nothing to trap.

This can happen when you copy and paste code from one form to another. You will see the event procedure in the form, but the Event itself is not registered. I do think this is fixed in A 2016. I noticed if I paste code in the form the events are registered with "[Event Procedure]"

I see what you mean. As far as I can see, all of my command buttons still have the [event procedure] in the onclick property.
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
Update:

So I had previously imported the .mdb in to a new blank database in Access 2010. However I never put this in to use. I have imported this .accdb in to the new version of 365, and the command buttons are now working OK.

The references and trusted location are still the same, so I'm not certain what was causing the problem.

I am going to import the most recent .mdb in to access 2010, saved as a .accdb, and then import this in to Office 365. Hopefully this will all go well

So forget the above. I opened a version of the database that worked completely fine. I closed it, and now I've no idea what copy it was that was working OK. So I am back to square one.

If anybody has any tips that would be great.

Thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:08
Joined
May 21, 2018
Messages
8,525
The fact that "[Event Procedure]" exists seems to suggest a problem in the compiled code. Only thing I can guess. When you convert it, it is not compiling correctly. I would do a full decompile, recompile, compact and repair.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:08
Joined
Feb 19, 2002
Messages
43,223
Although converting as you did is not wrong, there is an easier method.

Open the .mdb
Open any code module and compile the db.
Fix ALL compile errors
Save
then save again using the save as .accdb option.

This copies all the settings as well as all the objects.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:08
Joined
May 21, 2018
Messages
8,525
I would do the above and do the conversion, and then still copy all objects into a new accdb. I would then still decompile just to be extra safe. (That is suspenders and a belt).
 

kevnaff

Member
Local time
Today, 14:08
Joined
Mar 25, 2021
Messages
141
Although converting as you did is not wrong, there is an easier method.

Open the .mdb
Open any code module and compile the db.
Fix ALL compile errors
Save
then save again using the save as .accdb option.

This copies all the settings as well as all the objects.

Hi Pat.

I opened up my stable .mdb that I know is the latest version we are using. I open the VBA editor using ctrl + g. The option to compile under the debug option was greyed out.

I then saved the .mdb as a .accdb. Opened the .accdb and compiled the database. This was all done in Office 2010, and it all works OK at this point.

I then open the same.accdb in Office 365. I compiled the database again. It opens as normal, but then the command buttons do not work.
 

Users who are viewing this thread

Top Bottom