We help IT Professionals succeed at work.

MS Access Custom Toolbar Button Control

COPUSER
COPUSER asked
on
Experts,

I placed a custom toolbar ("myToolBar") with several standard buttons (Add, Edit, Delete, Save, Undo).  When the user clicks "Add" button for instance, I want the following: 1) Add button is in pressed state, Edit button is disabled, Delete button is disabled, and Save button is enabled.  I want to do something like this for all  other buttons.  How do I do this?  I'm running Access 2003.  I've tried the following and it gave a Runtime error 451 (property let procedure not defined and property get procedure did not return an object)


Private Sub myToolbar_ButtonClick(ByVal Button As Object)
    Select Case Button.Key
        Case "Add": MsgBox "Add clicked"
            Button(3).SetFocus
            Button(3).Enabled = False
            myToolbar.Controls("Edit").Enabled = False
Comment
Watch Question

Database Architect / Application Developer
Top Expert 2007
Commented:
Just an FYI.  If you use the technique (no code required) below, and use the built in items for Add, Delete, Undo, etc., which you can drag from any other built in menu/Toolbar, they will automatically be in the desired state depending on what is happening on a form at a given moment. In other words, they will act just like built in menus/toolbar.  You are simply build a custom bar.

Easily create real, professional Windows menus, toolbars and Right Click menus.

This works in the A2003 (and prior) environment and MDB format.  And they will port (with MDB) into A2007/10 environment and show up on the Add-Ins Ribbon.

Everything you need is here - no code ... see this link:

http://www.jamiessoftware.tk/articles/menubars.html
       
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
If you need more control (and it sounds like you do), then you'll have to use VBA to get to those buttons.

To enable/disable a button:

Commandbars("YourCommandBar").Controls("YourButtonName").Enabled = True
Commandbars("YourCommandBar").Controls("YourButtonName").Enabled = False

One trouble you'll have is if you use Nested buttons (i.e. submenus). If you do, you'll have to work down through the levels to find that button. For example, if I have a menubar named "MyMenuBar", and I have a submenu named "Tools", which has a button named "Delete", I'd have to do this:

Commandbars("MyMenuBar").Commandbars("Tools").Controls("Delete").Enabled = False

How to Dim Menuitems:
http://support.microsoft.com/kb/198464

Working with Commandbars:
http://msdn.microsoft.com/en-us/library/aa141034%28v=office.10%29.aspx



Author

Commented:
I've requested that this question be deleted for the following reason:

I decided to abandon the use of toolbar and instead use rows of command buttons.  Thanks for input, though.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Did you check out the link I posted ... it's reeeeeally easy to create menus.  I have (and still do) created 100's.

mx

Author

Commented:
Sorry Database MX,

It was something I wanted to tinker with mainly because it was new to me.  I really did not find too much value in using the toolbar approach to my application.  
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
You asked how to enable/disable commandbar buttons and you were given the steps to do this. Deleting this question because you decided to go another way really isn't an option - you were given sound advice, and you should review that advice and accept solutions.

Author

Commented:
LSM Consulting

The "sound advice" you've mentioned was nothing more than the Microsoft websites which I have already took a look at.  I am sorry if I am not smart enough to figure out how to do these things by reviewing the MS websites but I feel that I wasn't given the kind of answer I had been receiving from other experts in the past.  And since I have decided to abandon the question even before I actually tried the "sound advice" solutions, I don't think I owe anyone a point.   If anybody believes that partial points (I don't what is reasonable) are warranted for simply putting up some comments regardless of its value to the posted question than that person can all the points. Personally, I think its a bit petty.
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
Commented:
HUH???

You didn't really have to figure anything out. The code snippets I provided you showed you how to enable/diable the buttons (I use EXACTLY that same syntax in several of my Access apps, and it works), but you would (of course) have to construct those correctly, using the correct control names and such. I included the site links so that you'd have a reference to all the properties and methods available for use with the CommandBars object, as there are a LOT of them.

"And since I have decided to abandon the question even before I actually tried the "sound advice" solutions, I don't think I owe anyone a point."

I do apologize for my oversight. I did forget to consult my crystal ball before taking the time to post a comment. Next time, I'll be sure to do that so that I can insure that you still need a solution to the issue before volunteering any more of my time to your issues (note I said "volunteering" - we don't get paid anything to participate here).










Author

Commented:
LSMConsulting has really opened my eyes. I think both LSMConsulting and DatabaseMX deserve to share the full credit and the points.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
You can use my approach in A2003 and you will LSM's approach in A2010 (if using accdb).
So, win/win.  Note that all A2003 'bars' WILL import into A2010 to the Add-Ins Ribbon.

mx