Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 31st, 2006, 05:37 PM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default Call a Function

Hi,
 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.

Thanks,
Dave

Reply With Quote
  #2 (permalink)  
Old November 1st, 2006, 09:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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()
    MyFunction
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.

HTH,

Bob




Reply With Quote
  #3 (permalink)  
Old November 2nd, 2006, 10:38 AM
Friend of Wrox
 
Join Date: May 2006
Location: Jonesboro, AR, USA.
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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!

Thanks!:D
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.