Access 2007 Ribbon

C

ChoonBoy

I am trying to convert a button to an item in the new Ribbon.

When I select it in the ribbon, it should give the same effect as the
button. I have not been successful and appreciate any help.

I tried to work my way with this Example I got from the net but when I run
debug I get error (User-defined type not defined), I have no missing
references.

Public Sub OnCloseCurrentObject(control As IRibbonControl)

DoCmd.close CurrentObjectType, CurrentObjectName
End Sub

Code in Button (to be converted to Ribbon)

Private Sub cmddefault_Click()
DoCmd.close acForm, "frmstart"
Me!number.Top = Forms!frmdefault!Numbertop * 50
Me!number.Left = Forms!frmdefault!NumberLeft * 50
Me!txtdayZero.Top = Forms!frmdefault!D1top * 50
Me!txtdayZero.Left = Forms!frmdefault!D1Left * 50
Me!txtdatZero2.Top = Forms!frmdefault!D2top * 50
Me!txtdatZero2.Left = Forms!frmdefault!D2Left * 50
Me!txtMthZero.Top = Forms!frmdefault!M1top * 50
Me!txtMthZero.Left = Forms!frmdefault!M1Left * 50
Me!txtMthZero2.Top = Forms!frmdefault!M2top * 50
Me!txtMthZero2.Left = Forms!frmdefault!M2Left * 50
Me!txtyrZero.Top = Forms!frmdefault!Y1top * 50
Me!txtyrZero.Left = Forms!frmdefault!Y1Left * 50
Me!txtyrZero2.Top = Forms!frmdefault!Y2top * 50
Me!txtyrZero2.Left = Forms!frmdefault!Y2Left * 50
Me!cboName.Top = Forms!frmdefault!Nametop * 50
Me!txtname.Top = Forms!frmdefault!Nametop * 50
Me!cboName.Left = Forms!frmdefault!NameLeft * 50
Me!txtname.Left = Forms!frmdefault!NameLeft * 50

End Sub

Thanks in advance.
 
A

Albert D. Kallal

ChoonBoy said:
I am trying to convert a button to an item in the new Ribbon.

When I select it in the ribbon, it should give the same effect as the
button. I have not been successful and appreciate any help.

I tried to work my way with this Example I got from the net but when I run
debug I get error (User-defined type not defined), I have no missing
references.

Public Sub OnCloseCurrentObject(control As IRibbonControl)

DoCmd.close CurrentObjectType, CurrentObjectName
End Sub

Code in Button (to be converted to Ribbon)

Private Sub cmddefault_Click()
DoCmd.close acForm, "frmstart"
Me!number.Top = Forms!frmdefault!Numbertop * 50
Me!number.Left = Forms!frmdefault!NumberLeft * 50
Me!txtdayZero.Top = Forms!frmdefault!D1top * 50
Me!txtdayZero.Left = Forms!frmdefault!D1Left * 50
Me!txtdatZero2.Top = Forms!frmdefault!D2top * 50
Me!txtdatZero2.Left = Forms!frmdefault!D2Left * 50
Me!txtMthZero.Top = Forms!frmdefault!M1top * 50
Me!txtMthZero.Left = Forms!frmdefault!M1Left * 50
Me!txtMthZero2.Top = Forms!frmdefault!M2top * 50
Me!txtMthZero2.Left = Forms!frmdefault!M2Left * 50
Me!txtyrZero.Top = Forms!frmdefault!Y1top * 50
Me!txtyrZero.Left = Forms!frmdefault!Y1Left * 50
Me!txtyrZero2.Top = Forms!frmdefault!Y2top * 50
Me!txtyrZero2.Left = Forms!frmdefault!Y2Left * 50
Me!cboName.Top = Forms!frmdefault!Nametop * 50
Me!txtname.Top = Forms!frmdefault!Nametop * 50
Me!cboName.Left = Forms!frmdefault!NameLeft * 50
Me!txtname.Left = Forms!frmdefault!NameLeft * 50

End Sub

Thanks in advance.
 
A

Albert D. Kallal

Assuming you have a custom ribbon?

It not clear if you going to have that ribbon load JUST for that one form?

Anyway, the XML for the button in the ribbon would be:

<button id="MyDefaut" label="Defaults"
onAction="=cmdDefault()"/>


Then, in your form you can have:

Public Function cmddefaul()
DoCmd.close acForm, "frmstart"
Me!number.Top = Forms!frmdefault!Numbertop * 50

....rest of your code goes here unchanged....

End Function.

So, just chage the button code to pubic function from the current "sub" that
it is now.
This code can and should remain in the forms module. So, you don't have to
change the code.

And, your xml for the button code is as above..and when the button on the
ribbon is pressed, it will run your function in the form...
 
A

Albert D. Kallal

Wow...having keyboard follies today!!

(my sorry...)

Public Function cmddefaul()

Anyway, Above should read:

Public Function cmdDefault()


The whole point here is that a ribbon button can easily call a function in a
standard form, just remember that the code in the form as to be declared as
a function, and must be a public function.

So, as per your example, you can keep the code you have...just re-name the
button "sub" code to a public function (so, you wrap you code in a function
now, not a sub).

You could also keep your button code and have both the ribbon + button on
the form do the same thing (just create a public function that calls the
sub)
 
C

ChoonBoy

Thanks for your quick reply,

The ribbon will be for just one form.

I changed the sub to
Public Function cmddefault()

-code-

End Function.

My XML was also changed accordingly. Debug also ok.

But I get an error,

Can't run the macro or Callback function cmddefault()
Make sure the macro or function exists and takes the correct parameters.

All spellings checked ok.

Thanks
 
C

ChoonBoy

Hi Albert, sorry I missed out the equal sign after the double quote .
"=cmddefault()

It is working very well now.

Thanks
 
T

Tim

Hi Albert,

I'm wondering if you can assist me with an error i'm getting, i'm using the
MS page at: http://msdn.microsoft.com/en-us/library/aa338202.aspx as the
basis for my code, which is as follows:

i have an XML script that creates the ribbon:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="dbTabCORE" label="CORE Accounts" visible="true">
<group id="dbBusiness" label="Select Business">
<comboBox id="BusinessCombo" label="Select Business"
onChange="HandleOnAction">
<item id="ID1" label="Core Intelligence Solutions" />
<item id="ID2" label="Home" />

</comboBox>
</group>
<group id="dbCashBook" label="Cash Book">
<button id="CashBook" label="Manage Cash Book"
onAction="OpenCashBook"/>
<button id="Invoices" label="Invoices" onAction="OpenInvoices"/>
</group>
<group id="dbJobs" label="Job Management">
<button id="ViewJobs" label="Add/Edit Jobs" onAction="Jobs"/>
</group>
<group id="dbImport" label="Import">
<button id="AccountImport" label="Import Accounts"
onAction="AccountImport"/>
<button id="CashBookImport" label="Import Cash Book"
onAction="CashBookImport"/>
</group>
<group id="dbBudget" label="Budget">
<button id="AddBudget" label="Add Budget" onAction="AddBudget"/>
<button id="Budget" label="Manage Budget" onAction="Budget"/>
</group>
<group id="dbReports" label="Reports">
<button id="CashFlowReport" label="Cash Flow Report"
onAction="ReportCashFlow"/>
<button id="PositionReport" label="Financial Position Report"
onAction="ReportPosition"/>
<button id="BalanceSheetReport" label="Balance Sheet Report"
onAction="ReportBalanceSheet"/>
</group>
<group id="dbSystemAdmin" label="Administer CORE Accounts">
<button id="BusinessList" label="Add/Edit Customers"
onAction="Business"/>
<button id="Accounts" label="Add/Edit Bank Accounts"
onAction="Accounts"/>
<button id="PaymentCat" label="Add/Edit Payment Categories"
onAction="PaymentCat"/>
<button id="ReceiptCat" label="Add/Edit Receipt Categories"
onAction="ReceiptCat"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

and a sub that i am tryiing to use to trigger when the user changes the
value in the combox on the ribbon, as follows:

Public Function HandleOnAction(control As IRibbonControl)

MsgBox control.ID

End Function

but the error i get is that the function has the wrong number of arguements.
How can i get the IRibbonControl to be passed to the function?

Thanks for the hlp.

Tim
 
Top