Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command button for VBA module

Status
Not open for further replies.

TracySHC

MIS
May 5, 2005
66
US
I'm new to Access, and I'm not sure how to proceed on this issue. I have written a Visual Basic module, and would like for the users to run the module by clicking on a button. How do you create a command button that will run a module?
Thank you for any and all advice,
TracySHC
 
Have a look at the Click event procedure of the Commandbutton object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
For example, if you have a function in your module called fctnTest you can run this from your command button by putting =fctnTest() in the OnClick property of the button.

Alternativelym you can write an event procedure for the button that calls the function. This allows you to do other stuff with the button click as well as runn the function, e.g.
Code:
Private Sub NameOfYourButtonHere_Click()
On Error GoTo Err_NameOfYourButtonHere_Click

    'Do some stuff here if you want
    fctnTest() 'Call your function
    'Do more stuff here if you want
Exit_NameOfYourButtonHere_Click:
    Exit Sub

Err_NameOfYourButtonHere_Click:
    MsgBox Err.number & ": " & Err.Description, vbExclamation
    Resume Exit_NameOfYourButtonHere_Click
    
End Sub
Hope this helps.

[pc2]
 
mp9 and PHV,
Thank you both for your input. MP9, I've tried both of your suggestions, but I receive the error message that my procedure cannot be found. I've changed the procedure from a private sub to a public function, and still receive the same error. Any ideas?
Thank you again for your help,
TracySHC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top