By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,504 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,504 IT Pros & Developers. It's quick & easy.

calling Sub in Module

100+
P: 553
If you write a Sub/Function , called "ASub" in a module and call the module "Module2"

If from the form, a button is clicked, how can i call "ASub"
Jul 19 '07 #1
Share this Question
Share on Google+
5 Replies


JKing
Expert 100+
P: 1,206
Module2
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Sub ASub()
  5.     MsgBox "You just called ASub in Module 2"
  6. End Sub
  7.  
Command_Click()
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command_Click()
  2.     Call ASub
  3. End Sub
  4.  
Jul 19 '07 #2

100+
P: 553
any idea why i am getting error:

"Sub of Function not defined"

i have similar way to yours

Module2
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Public Sub ASub()
  5.     MsgBox "You just called ASub in Module 2"
  6. End Sub
  7.  
Command_Click()
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command_Click()
  2.     Call ASub
  3. End Sub
  4.  
Jul 19 '07 #3

100+
P: 553
Its works now...... I made Sub Private before,.
any idea why i am getting error:

"Sub of Function not defined"

i have similar way to yours
Jul 19 '07 #4

100+
P: 553
HI

If in the module code, i have to refer to a textfield located on a form, how would i do that.

for example, a form is called:
my_form

It has a textfield , TextBox0

In the module code, i have to set value of TextBox0.... I cant do Me.TextBox0

I have tried doing my_form.TextBox0 - but doth the ways seems not to work


help!
thanks


Its works now...... I made Sub Private before,.
Jul 20 '07 #5

Expert 100+
P: 344
HI

If in the module code, i have to refer to a textfield located on a form, how would i do that.

for example, a form is called:
my_form

It has a textfield , TextBox0

In the module code, i have to set value of TextBox0.... I cant do Me.TextBox0

I have tried doing my_form.TextBox0 - but doth the ways seems not to work


help!
thanks
Simplest way would be to have your code in the forms module, rather than a global module. That way, the code can refer directly to TextBox0

If the code has to be global (because it is called from many forms) then pass TextBox0 as a variable to the code, byRef, so it can be changed.
i.e.
Expand|Select|Wrap|Line Numbers
  1. sub mycode (byRef textbox as string)
  2.  
Jul 20 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.