Wrox Programmer Forums
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 31st, 2006, 05:37 PM
Friend of Wrox
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default Call a Function

 I've written 5 functions each in its own module. I want to make one form with buttons on it and use click events to trigger the functions. What piece of code do I need to do this? I thought it would be something simple like Call Function(myfunction) but I haven't found anything that works yet.


Old November 1st, 2006, 09:30 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts

If you have a function defined in a standard module like:

Public Sub MyFunction()
    MsgBox "MyFunction called."
End Sub

The click event on your form would call it like:

Private Sub Command0_Click()
End Sub

Or you could use:

Private Sub Command0_Click()
    Call MyFunction
End Sub

MyFunction needs to be defined with public scope. All there us to it.



Old November 2nd, 2006, 10:38 AM
Friend of Wrox
Join Date: May 2006
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts

Great! Thanks Bob that worked.
I knew it had to be something simple.
I had it set up like:

Function MyFunction()
Do this stuff
End Function

So I just changed Function to Sub and made it Public like you suggested and it works.
And best of all, I don't have to use any macros!


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call to function Awkuzu BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 19th, 2007 06:13 PM
Unable to call function... rupen Javascript How-To 1 July 1st, 2006 04:53 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
Help with Javascript function call fakeeyed Javascript 1 January 15th, 2006 04:27 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.