Adding a button on a form to run various code....

  • Thread starter Thread starter rfuscjr via AccessMonster.com
  • Start date Start date
R

rfuscjr via AccessMonster.com

I inhereted a form that essentiall has a button for each of a dozen or so
monthly reports. Someone needs to hit each button and answer some query
prompts and the report will be generated. I have worked to elimnate all
prompts, may of which were prompts for fiscal year and such that could be
determined in the query.

I do not want to cut and paste all the code behind all the buttons into one
big master run button. I would though like to create one button that would
run all the reports. Is there vba code that essentially would say: 'Press a
report button'. I'd then repeat the code for each of the dozen report
buttons and be done with it.
 
If all the reports are the same, use one report based on a parameter query.
For example, put [Enter Fiscal Year] in the criteria of the FiscalYear
field. When you open the report, a dialog will open asking you to enter the
fiscal year.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
If you are fairly proficient with VBA, I can suggest a fairly elegant way
that would allow the user to run any combination of the available reports.

I would use a multi select list box to display the available reports, allow
the user to select the report(s) to run, and a command button to actually run
the reports.

You would do that by iterating throught the list box's ItemsSelected
collection and using the OpenReport method for each. There is a good example
of how to use the ItemsSelected collection in VBA Help.

If you have any questions on the details, post back.
 
If only it were that easy. Each button has a little something unique behind
it. All reports are different. Some buttons actually create Excel
spreadsheets, some Access reports, some have extensive VBA, some reference
and run queries in the db. I really just want to create a new single button
that essentially says: Click button 1, Click button 2 etc etc.
If all the reports are the same, use one report based on a parameter query.
For example, put [Enter Fiscal Year] in the criteria of the FiscalYear
field. When you open the report, a dialog will open asking you to enter the
fiscal year.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
I inhereted a form that essentiall has a button for each of a dozen or so
monthly reports. Someone needs to hit each button and answer some query
[quoted text clipped - 10 lines]
report button'. I'd then repeat the code for each of the dozen report
buttons and be done with it.
 
All need to be run...just looking for a quick way to eliminate hitting 12
buttons. Just want a single button that 'clicks' each of the 12 for me...so
to speak.
If you are fairly proficient with VBA, I can suggest a fairly elegant way
that would allow the user to run any combination of the available reports.

I would use a multi select list box to display the available reports, allow
the user to select the report(s) to run, and a command button to actually run
the reports.

You would do that by iterating throught the list box's ItemsSelected
collection and using the OpenReport method for each. There is a good example
of how to use the ItemsSelected collection in VBA Help.

If you have any questions on the details, post back.
I inhereted a form that essentiall has a button for each of a dozen or so
monthly reports. Someone needs to hit each button and answer some query
[quoted text clipped - 7 lines]
report button'. I'd then repeat the code for each of the dozen report
buttons and be done with it.
 
If the button to run all the reports - MasterButton- is on the same form
then you can call the code for each button in the master button's click
event.

Private Sub MasterButton_OnClick()

Button1_OnClick()
Button2_OnClick()

End Sub

If the MasterButton is not on the form, then you will have to make sure the
form is open and that all the relevant subs are Public.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Same form..I will try this...THANKS!!!!!!

John said:
If the button to run all the reports - MasterButton- is on the same form
then you can call the code for each button in the master button's click
event.

Private Sub MasterButton_OnClick()

Button1_OnClick()
Button2_OnClick()

End Sub

If the MasterButton is not on the form, then you will have to make sure the
form is open and that all the relevant subs are Public.
I inhereted a form that essentiall has a button for each of a dozen or so
monthly reports. Someone needs to hit each button and answer some query
[quoted text clipped - 10 lines]
report button'. I'd then repeat the code for each of the dozen report
buttons and be done with it.
 
The syntax does not work. I add a new button, and define the event as shown
below substituting my button names. It does not like the syntax at all. Oh
well...maybe there is a way to execute the event procedure associated with
each button....?

John said:
If the button to run all the reports - MasterButton- is on the same form
then you can call the code for each button in the master button's click
event.

Private Sub MasterButton_OnClick()

Button1_OnClick()
Button2_OnClick()

End Sub

If the MasterButton is not on the form, then you will have to make sure the
form is open and that all the relevant subs are Public.
I inhereted a form that essentiall has a button for each of a dozen or so
monthly reports. Someone needs to hit each button and answer some query
[quoted text clipped - 10 lines]
report button'. I'd then repeat the code for each of the dozen report
buttons and be done with it.
 
My fault. No enough stimulants in my system or too many stimulants in my
system or memory glitch.

Button1_Click '<<< No Parens and proper name for sub

Alternative syntax
Call Button1_Click

Basically you need to call the sub or function that is running the code in
the form - from the form.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

rfuscjr via AccessMonster.com said:
The syntax does not work. I add a new button, and define the event as
shown
below substituting my button names. It does not like the syntax at all.
Oh
well...maybe there is a way to execute the event procedure associated with
each button....?

John said:
If the button to run all the reports - MasterButton- is on the same form
then you can call the code for each button in the master button's click
event.

Private Sub MasterButton_OnClick()

Button1_OnClick()
Button2_OnClick()

End Sub

If the MasterButton is not on the form, then you will have to make sure
the
form is open and that all the relevant subs are Public.
I inhereted a form that essentiall has a button for each of a dozen or so
monthly reports. Someone needs to hit each button and answer some query
[quoted text clipped - 10 lines]
report button'. I'd then repeat the code for each of the dozen report
buttons and be done with it.
 
Back
Top