dbTalk Databases Forums  

Code for a save button on the ribbon for all forms

comp.databases.ms-access comp.databases.ms-access


Discuss Code for a save button on the ribbon for all forms in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
PW
 
Posts: n/a

Default Code for a save button on the ribbon for all forms - 06-06-2012 , 01:34 PM






Hi,

I want to have the usual save, edit, new, etc.. buttons on the ribbon
instead of on each form. How would I go about that? And, I need to
run an different form edit routine for each form as the control names
will be different,....

-paulw

Reply With Quote
  #2  
Old   
Albert D. Kallal
 
Posts: n/a

Default Re: Code for a save button on the ribbon for all forms - 06-06-2012 , 02:52 PM






"PW" wrote in message news:ug8vs7pg98ghh366aubr1tnvsh255hgc7i (AT) 4ax (DOT) com...

Quote:
Hi,

I want to have the usual save, edit, new, etc.. buttons on the ribbon
instead of on each form. How would I go about that? And, I need to
run an different form edit routine for each form as the control names
will be different,....

-paulw
The simple solution here is to not use a a call back routine. Simply place
the functions as public in each form. The form with the focus will thus run.

So the on-action of the ribbon would be:

=MyPublicFunctionName()

Note CAREFULLY how we have = and () (you must have these), and they must be
under the quotes.

Eg for the xml we have:
onAction="=MyDelete()"

So a public function called MyEdit would be local to each form. This allows
the use of "me", means the code is in each form so the code can deal with
different field names etc.


So using public functions in place of a SUB with call backs not only solves
your problem of one ribbon running different code depending on what form has
the focus but such an approach also means that the code for each form can be
placed in each form and not have to be a public SUB in a standard code
modules like a ribbon call back.

Note you can also pass values from the ribbon if you wanted. So a ribbon
with a bunch of buttons to launch a report would look like:

And note that the public does not have to be placed in the form and thus
functions in standard code modules become global (forms are searched first,
and if function not found then the public code modules are searched).

So for a few buttons on a ribbon to launch/display reports we create a
public function in standard code module:

Public Function MyOpenReport(strR As String)

DoCmd.OpenReport strR, acViewPreview

End Function

Then XML for ribbon would be:

onAction="=MyOpenReport('rptDailySalesTotal')"


Note how I used single quotes to pass the report name. So for above this
means for each button you place on the ribbon you don't have to write any
additional VBA code to launch a report.


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
PleaseNoSpam_kallal (AT) msn (DOT) com





--
Albert D. Kallal
Edmonton, Alberta Canada
PleaseNoSpam_kallal (AT) msn (DOT) com

Reply With Quote
  #3  
Old   
PW
 
Posts: n/a

Default Re: Code for a save button on the ribbon for all forms - 06-06-2012 , 05:26 PM



On Wed, 6 Jun 2012 13:52:18 -0600, "Albert D. Kallal"
<PleaseNOSpamkallal (AT) msn (DOT) com> wrote:

Quote:
"PW" wrote in message news:ug8vs7pg98ghh366aubr1tnvsh255hgc7i (AT) 4ax (DOT) com...

Hi,

I want to have the usual save, edit, new, etc.. buttons on the ribbon
instead of on each form. How would I go about that? And, I need to
run an different form edit routine for each form as the control names
will be different,....

-paulw

The simple solution here is to not use a a call back routine. Simply place
the functions as public in each form. The form with the focus will thus run.

So the on-action of the ribbon would be:

=MyPublicFunctionName()

Note CAREFULLY how we have = and () (you must have these), and they must be
under the quotes.

Eg for the xml we have:
onAction="=MyDelete()"

So a public function called MyEdit would be local to each form. This allows
the use of "me", means the code is in each form so the code can deal with
different field names etc.


So using public functions in place of a SUB with call backs not only solves
your problem of one ribbon running different code depending on what form has
the focus but such an approach also means that the code for each form can be
placed in each form and not have to be a public SUB in a standard code
modules like a ribbon call back.

Note you can also pass values from the ribbon if you wanted. So a ribbon
with a bunch of buttons to launch a report would look like:

And note that the public does not have to be placed in the form and thus
functions in standard code modules become global (forms are searched first,
and if function not found then the public code modules are searched).

So for a few buttons on a ribbon to launch/display reports we create a
public function in standard code module:

Public Function MyOpenReport(strR As String)

DoCmd.OpenReport strR, acViewPreview

End Function

Then XML for ribbon would be:

onAction="=MyOpenReport('rptDailySalesTotal')"


Note how I used single quotes to pass the report name. So for above this
means for each button you place on the ribbon you don't have to write any
additional VBA code to launch a report.


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
PleaseNoSpam_kallal (AT) msn (DOT) com

So Cool Albert! Thanks!

-paul

Reply With Quote
  #4  
Old   
PW
 
Posts: n/a

Default Re: Code for a save button on the ribbon for all forms - 07-05-2012 , 09:33 PM



On Wed, 6 Jun 2012 13:52:18 -0600, "Albert D. Kallal"
<PleaseNOSpamkallal (AT) msn (DOT) com> wrote:

Quote:
"PW" wrote in message news:ug8vs7pg98ghh366aubr1tnvsh255hgc7i (AT) 4ax (DOT) com...

Hi,

I want to have the usual save, edit, new, etc.. buttons on the ribbon
instead of on each form. How would I go about that? And, I need to
run an different form edit routine for each form as the control names
will be different,....

-paulw

The simple solution here is to not use a a call back routine. Simply place
the functions as public in each form. The form with the focus will thus run.

So the on-action of the ribbon would be:

=MyPublicFunctionName()

Note CAREFULLY how we have = and () (you must have these), and they must be
under the quotes.

Eg for the xml we have:
onAction="=MyDelete()"

So a public function called MyEdit would be local to each form. This allows
the use of "me", means the code is in each form so the code can deal with
different field names etc.


So using public functions in place of a SUB with call backs not only solves
your problem of one ribbon running different code depending on what form has
the focus but such an approach also means that the code for each form can be
placed in each form and not have to be a public SUB in a standard code
modules like a ribbon call back.

Note you can also pass values from the ribbon if you wanted. So a ribbon
with a bunch of buttons to launch a report would look like:

And note that the public does not have to be placed in the form and thus
functions in standard code modules become global (forms are searched first,
and if function not found then the public code modules are searched).

So for a few buttons on a ribbon to launch/display reports we create a
public function in standard code module:

Public Function MyOpenReport(strR As String)

DoCmd.OpenReport strR, acViewPreview

End Function

Then XML for ribbon would be:

onAction="=MyOpenReport('rptDailySalesTotal')"


Note how I used single quotes to pass the report name. So for above this
means for each button you place on the ribbon you don't have to write any
additional VBA code to launch a report.


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
PleaseNoSpam_kallal (AT) msn (DOT) com

Okay - digging this not using a callback. But I want a combobox(es)
on the ribbon where the user can search for a client from last name,
states, etc..... And once the user gets to the record - nevermind
that doesn't make sense. The changes would be recorded but what if
he/she changed the last name or whatever?

But after the user creates a new record, I need to have the combobox
on the ribbon refresh with the new record.

I have been studying the Ribbon chapter in the 2010 Programmer's
Reference guide but the author of that chapter just uses callbacks
(like AccessRibbons website does).

-paul

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.