Pass variable to command button on click event on form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to pass the value of variable from a function to command
button on a form so that the value of the variable will determine the action
taken such as below:

Sub CommandButton_Click(stRpt)
If stRpt="First" then
Do First Report
Elseif stRpt="Second" then
Do Second Report
End If
End Sub

Or perhaps there is a better approach. Any help will be appreciated.

I apologize if this is a duplicate post. I'm not sure my first one went
through.
 
Since you are not calling the function directly, it would not know the value
of the variable. The easiest way would be to Dim the variable at the module
level (at the top of your form module right below the Option statements)
Then it is visible from any place in the form's code.
 
Back
Top