Solved

MS Access 2010 ribbon

Posted on 2013-05-16
12
1,035 Views
Last Modified: 2013-05-27
Hello,
I would like to be able to disable / enable (in code) some of the built-in buttons, e.g. "Print" or "Quick Print" in my custom ribbon in MS Access 2010.

Example would be much appreciated.

Thanks!!
0
Comment
Question by:flsolo
  • 8
  • 3
12 Comments
 
LVL 70

Expert Comment

by:KCTS
Comment Utility
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
The Q noted by KCTS is very long.
But at the end of it, you should have a very good idea of what's involved in customizing the Ribbon.

Now, your question was  
I would like to be able to disable / enable (in code) some of the built-in buttons, e.g. "Print" or "Quick Print" in my custom ribbon in MS Access 2010.

I wouldn't do that.  Since you've got a custom ribbon on the go, I'd populate it with buttons aimed at macros/code that do what YOU want.  That will give you the level of control that you want, without having to fight the system's built in tendency to think that it knows what's best.

A sample db from you would be most helpful.

Nick67
0
 

Author Comment

by:flsolo
Comment Utility
Nick67,
Attached is the ms access db with all buttons on one ribbon. There is a button "Test 2" which works exactly as I need to - it is a custom button. I need to get working built-in buttons "Print" and "Quick Print" the same way, i.e. enable them when any report is shown and disable them when Form1 is shown.

Any help is appreciated.
Thank you.
Test2.zip
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
I'll have a look at it this evening, but
I need to get working built-in buttons "Print" and "Quick Print" the same way
will be ultimately self-defeating.  Those buttons will only work the way MS wants them to.  Your only simple choices are to hide built-in buttons, or display them and let them work the way MS intended.  While it may not be technically impossible to figure out which built-in button was pressed, cutoff its event at the knees, and substitute your own event, it's REALLY not going to be worth the effort
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
If you REALLY have to have that kind of functionality, and have access to VSTO then you can take a gander at this
http://msdn.microsoft.com/en-us/library/vstudio/bb608623.aspx
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Alright here's a little jiggery-pokery of the Ribbon and BackStage
The Print and Quick Print look like they're MS's, but they are ours.
I am not at all sure that your events are working the way you desire, but I have put some msgboxes into them to show they are firing.  Control.tag seems to be empty, so nothing goes on.

I have hidden the BackStage, but it throws a one-time unhappy error when accessesd from an open form, whining about TabShare  The USysRibbons XML has been formatted for legibility.  You also have a control disabling problem when you close out a report--the Ribbon controls are NOT disabled until a new object is actually made the focus.

Let me know what you think.

Nick67
Nick1.accdb
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Alright,
That BackStage error existed in your original as well.
To get rid of it, look here
http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/c058c185-4076-4670-b7eb-b51100a10388

In Options | Client Settings turn off Show add-in user interface errors

Because the forms don't have a share tab, what you've done to pare down BackStage pops an error when a non-existent tab is made invisible.
0
 

Author Comment

by:flsolo
Comment Utility
Nick67,
Thanks for noticing that error, it has never happened to me.

The database Nick1.accdb works the way I want (for enabling / disabling print and quick print buttons), but when the report is shown, print button enabled and clicked, I want to show the print dialogue. Is it possible? The same with quick print - when enabled and clicked it prints (the report) to the windows default printer.

Thanks!
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
In Options | Client Settings turn off Show add-in user interface errors
From the look of the thread I posted, that option is set on a machine basis.  If it is off on your machine already, then you would have never seen the error.

The quick print should be  straight forward
DoCmd.OpenReport Screen.ActiveReport.Name, acViewNormal
ought to do it.

But if you liked the functionality behind those two print buttons, my customization of them was unnecessary.  You just need the Select Case True logic that I have set up to disable the MS buttons -- which is entirely doable.

You'd add the BackStage disablement XML to your existing USysRibbons so that no one can print from BackStage, and alter the Select Case True logic to point at the existing MS id's and not FakePrint and FakeQuickPrint

You could invoke a FileDialog object and its assorted rigamarole...but if you are perfectly happy with what MS's button does, why re-invent the wheel?
0
 
LVL 26

Expert Comment

by:Nick67
Comment Utility
Try this one
I think the buttons behave as you'd like
Nick1.accdb
0
 

Author Comment

by:flsolo
Comment Utility
Nick67,
Thanks for your post again, yes the buttons works the way I want. You deserve the points already, but would you please show me (db example is the best) how to do it with standard MS buttons as mentioned in your last post (that was my original question)?

Thanks!
0
 
LVL 26

Accepted Solution

by:
Nick67 earned 400 total points
Comment Utility
I did poke at that a bit...to learn that the MS buttons will NOT permit themselves to be disabled.  Apparently the idMSO bit in the XML tells the system to pointedly ignore anything the VBA code may tell it to do.

Ribbons are funny objects to manipulate with VBA.  The code doesn't behave the way you'd expect.  Putting breakpoints in the disablement code was useless.  The code would not stop for them.  Msgbox's worked, so you could see the code was firing, but the breakpoint would just be completely ignored.

You've got what you need--buttons that look like the MS ones but behave the way you want.
There is a listing of all the imageMso strings here
http://msdn.microsoft.com/en-us/library/dd953682(v=office.12).aspx
and a gallery of them here
http://soltechs.net/CustomUI/imageMso01.asp?gal=1&count=no
Which is certainly a lot more documentation than existed at the time that Q27231448 was posted.

So you should be able to mock up any MS button and make it behave how you want, which is certainly what the doctor ordered.  I think any effort to leave the idMso intact but then try to manipulate the resulting button will be wasted effort.

Nick67
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now