Buttons and Macros

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Can you, upon pressing a button within a form, run a
macro dependant upon another populated field within that
form (i.e. "if this field is x then run this macro
otherwise run this other macro").
 
Paul,

I believe you may be underestimating the valuable
resources that you have at your disposal, namely you work
colleagues.
 
Yes. You will need to use a bit of VBA code in On Click Event of the
command button to do this. In the event that you have not done much VBA
coding of events, here are the steps:

1. Right click on the desired Command Button (let's call it:
CommandRunMacro) control and select Properties.

2. When the Properties sheet opens, click the tab labeled Event.

3. In the grid below, locate the row labeled, On Click. It should be blank.
Click anywhere in the white space to the right of the label and you will see
a downward-pointing arrow appear, indicating that this is also a ComboBox.
Click the arrow and select "Event Procedure".

4. Then, notice that there is an ellipsis or three little dots (...) to the
right of the ComboBox. Click the ellipsis and you will open a code window.
You will see that Access has given you a space for entering some code in
this event - it will look something like the following:

Private Sub Private Sub CommandRunMacro_Click()

End Sub

5. After the "Private Sub Private Sub CommandRunMacro_Click()" line,
insert the following:

If Me!MyField = x then
DoCmd.RunMacro "MyMacro"
Else
DoCmd.RunMacro "MyOtherMacro"
End If

6. Click the Save icon and close the Microsoft Visual Basic code window.
 
Back
Top