473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

calling Sub in Module

553 512MB
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
5 2055
JKing
1,206 Expert 1GB
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
questionit
553 512MB
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
questionit
553 512MB
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
questionit
553 512MB
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
Lysander
344 Expert 100+
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

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

Similar topics

2
by: Marc Shapiro | last post by:
I am relatively new to python (I have used it on and off for a few small projects over the last few years) so I imagine that what I am trying to do has already been done, but practical experience,...
10
by: Kyler Laird | last post by:
I need to submit C/C++ code for a class. (It's not a programming class. The choice of language is inertial. I think that it mostly serves to distract students from the course subject.) I'm...
1
by: Stephen Kellett | last post by:
Hello everyone, I'm trying to do something in C calling Python and its failing. I'd be grateful if you could take a look and hopefully you have an answer. What I'm trying to do is determine...
5
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py" that defines some paths, variables etc. without...
6
by: jchao123 | last post by:
Dear All, I have an MDB file (Access 2000/XP) which contains generic routines I use in various apps (eg, API calls, File access classes etc). I have compiled into an MDE file which I reference...
1
by: Pete Straman Straman via AccessMonster.com | last post by:
Hey: I have created a module that runs fine. I am trying to put all my modules on a form. I cannot get the modules to run from the command buttons. The error I get is Compiler error: ...
1
by: Nick | last post by:
I have read many postings regarding the above thread but don't seem to have found the exact problem I am experiencing. I am using VS.NET and have 2 projects within the 1 solution. First project...
5
by: Amit | last post by:
I tried calling a subroutine in a fortran module from C ,but couldn't.I always get the error: undefined reference in the main.o file (main is in C calling the subroutine). for calling the...
6
by: johnf401 | last post by:
I've got a VB .NET Web application that has several frames (for discussion sake, let's call them Form1.aspx and Form2.aspx). I want to be able to call a code module in Form2.aspx.vb from code...
4
by: MLH | last post by:
I have the following saved UNION query named qryPeople2NameInNPaperAd: SELECT & " " & & " " & & " " & & ", " & & " " & AS Item, tblVehicleJobs.VehicleJobID FROM tblVehicleJobs INNER...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.