You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
Sue and I were talking the other day about Ribbon customizations with regard to some training materials that she is preparing for our support engineers. Along the way I mentioned command repurposing and how you could do some pretty cool stuff with it in Access applications. She suggested that this might make a good blog post and I think she's right.
I've been working on an application to track the work that I do throughout the year, and thought I would add a database password to encrypt the database. Since Access has this command built in on the Ribbon, I could use the idMso attribute of a button set to SetDatabasePassword to add this command to my database. Cool - however, adding a database password requires that the database is opened exclusively, and I didn't really want to see the built-in error message with the built-in command. Enter command repurposing.
Repurposing a command refers to the ability to use a built-in command in the Ribbon, but to provide your own functionality with that command. In my scenario, I wanted Access to encrypt the database, but I want my own error message when the database is not opened exclusively. To do this is actually quite simple. In the XML for the customization, specify the command that you want to repurpose using the command element. Then, specify the control that you want to use (in this case, the SetDatabasePassword button) in a Ribbon.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <commands> <command idMso="SetDatabasePassword" onAction="OnSetPassword"/> </commands> <ribbon> <tabs> <tab id="tabTab1" label="Password"> <group id="grpGroup1" label="Password"> <button idMso="SetDatabasePassword" size="large" label="Set Password"/> </group> </tab> </tabs> </ribbon></customUI>
</tab> </tabs>
Add this XML to a USysRibbons table and set the RibbonName property of the database to match the entry in the table.
The onAction callback of a repurposed command is slightly different from that of a regular control in that it allows you to indicate whether or not to cancel the default action of the built-in command. Add the following code for the OnSetPassword callback routine:
Public Sub OnSetPassword(control As IRibbonControl, ByRef CancelDefault) If (CurrentProject.Connection.Properties!Mode = 12) Then CancelDefault = False Else MsgBox "You must open the database exclusively to set the database password.", _ vbExclamation, "Cannot Set Password" CancelDefault = True End IfEnd Sub
If the database is opened exclusively (Mode=12), we'll allow the default action to continue by setting the CancelDefault parameter to False. If the database is not opened exclusively, we'll stop the built-in action by setting it this argument to True. To try this out, click the button in the new tab that was added by the customization.
Thanks Sue for the suggestion!
Comments: (8) Collapse
What is the name of the built-in command that's been repurposed?
And also...
why are onLoad="OnLoad" > and startFromScratch="false">
present here: msdn2.microsoft.com/.../bb462633.aspx
but not in the example you've given? How does one know when to use or not such pieces of code? Are there tutorials, books or is it just a trial-and-error procedure?
The name of the built-in command that I repurposed was 'SetDatabasePassword'. This command is specified in the idMso attribute. Good question about the onLoad and startFromScratch attributes. The onLoad attribute specifies a callback that is handled when a customization is first loaded. The parameter in the callback is an IRibbonUI object that is used to invalidate either the Ribbon or individual controls. Use the startFromScratch attribute to define a customization without any of the existing controls - in other words, 'from scratch'. A startFromScratch customization is often used for applications where you want to control the entire experience of the application. To include additional controls with the existing Ribbon for an Office application such as Access, specify startFromScratch=false. The example used here only shows a single button that has been repurposed. Specifying these attributes was not a requirement for my example so I omitted them. Hope this helps!
Rob
Thank you Rob, "The name of the built-in command that I repurposed was 'SetDatabasePassword'.
In your post, you say, "Then, specify the control that you want to use (in this case, the SetDatabasePassword button) in a Ribbon."
Does that mean that the button and the command have the same name?
Rob, I am trying to make your example and the one from Frank Rice, "Temporarily Repurpose Commands on the Office Fluent Ribbon" work in Visual Studio 2008 and Word 2007. I am using C# and can get the callback routine to work but setting CancelDefault = False does nothing. The default action of the built-in command does not work. Any ideas. Thanks, Patrick
Rob, I answered my own question. In the Rice article "Temporarily Repurpose Commands on the Office Fluent Ribbon" he has the C# code: "public void mySave(IRibbonControl control, bool cancelDefault)" but it is missing the "ref" part: public void mySave(IRibbonControl control, ref bool cancelDefault). What a difference one word can make. Thanks, Patrick
Thanks Rob.
I'm a bit confused here. If the command you're repurposing(i.e. assigning a different purpose to) is 'SetDatabasePassword', then why does the button that carries out the new purpose have the same name as the old purpose?
Yes, the button and the command have the same name. The command element in the commands section of the customization says "I want the command named 'SetDatabasePassword' to fire the specified onAction callback". Then, the button control is used with the 'SetDatabasePassword' idMso attribute to actually include the button in the customization. The command element only repurposes the command, it does not include the actual button in the Ribbon. Hope this helps!
Comments: (loading) Collapse