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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using modules 2

Status
Not open for further replies.

thompc

Technical User
May 29, 2002
4
GB
This may be pretty basic but it seems so simple that I cannot find the answer! I have successfully used access '97 for some time with some pretty complex reports and now want to add/use a module to do some simple frequently used calculations (like VAT). No matter how simple I make the module (the actual code is correct) I cannot get the module to be "seen" by any form or report. It is a standard module and i belive this is already Public. It will not even run in debug mode. How do I get my form or report or debug tool to "see" a module in the modules area? It has been compiled and saved.
 
Thompc,
Not sure if this will help or not. I'm not a programmer and I had the same difficulty until Gord Hubbell put me on the right track.
The main problem I had was naming the functions and the variables.
I try to name my modules "ONEWAY"
and the Function WAYONE ()
the variable is also named WAYONE and is referenced throughout the coding.
FOR EXAMPLE;
DIM A,B,C,D AS INTEGER
a=1
b=2
c=3
d=4
e=5
Function WAYONE()
WAYONE = d
A+b =c
WAYONE = D+c
e=b+c
WAYONE = D+c+e
END FUNCTION
Hope this helps it sure improved my results.
Jim

 
Copy and paste the code from the module here so we may take a look. If identified correctly it should be able to be called from your reports and forms.

Bob Scriver
 
thompc:

One thing I did wrong when I first started using modules was to name the module and the function the same. This resulted in Access getting very confused and not providing results as desired.

I have since used the format of naming the module the name of the function but using a bas prefix.

Module Name : basAgeCalc
Function Name: AgeCalc

Could this be the problem with your functions?

Another problem I inflict on myself is not defining the variables to hold the values being passed:

Public Function AgeSet()

If nothing is put between the parands the function will not work. So it should look like this:

Public Function AgeSet(DOB As Date, CalcDate as Date)

The two variables will hold the data passed by the calling query or routine.

Hope this helps. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Using modules is like using other call statements. the method Call MyFunction(dimmed statements) usually will direct your code to the correct function.

Check you have not included Private at the beginning of your sub or function. I write Function only no public or private.
 
Thanks to all respondents. The problem was indeed that I had named the module the same as the function inside. It is a nuisance that this "error" does not appear anywhere in the "Help"! and the message you get when you do this are totally misleading! As soon as I renamed my module FRED every became accessable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top