One last problem. In my test database, I set up a table
named ProfitTest with two fields: one was 'Cost" and the
other "Units."
Next, I wrote a Public Function called "Price" that
multiplies Cost * Units. I then wrote another Public
Function that calculates off the "Price" Function. It is
called "Score." It uses an IIF statement and provides a
score, depending on the results of the public
Function "Price."
Next, I designed a query that had four
columns: "Cost," "Units," "Price," and "Score." In the
query everything worked. A Price was calculated and the
Score worked. So, I thought all was fine. However, when
I went to save the query, no matter what I try to name the
query, it gives me an error message "Cannot open
database "my newly assigned name." It may not be an
application that your application recognizes, or the file
may be corrupt."
Then, I thought, well I probably haven't saved the Module
that the Public Function is in, therefore, the query
probably can't find the reference. So, I try to save the
module and it asks me to save the following
objects: "Module1" and "Query1." If I say "Yes," it
asks me to save the query and I am thrown back into the
error message I got when trying to save the query.
Could this be that I should have saved the Public Function
first in the module and then created the query and then
saved it? I'm thinking that since I didn't save either
and then tried to save both, that they were tied to each
other and couldn't find each other for the save operation,
although they seemed to find each other for the
calculation phase.
Sorry for the long question.
Ken
-----Original Message-----
Thanks! I have not worked with functions or VBA. I guess
I just need to read up on Functions syntax and create a
module that contains the functions. I guess The functions
would use the fields I reserve in my table? Or would I
create string functions with a Dim statement? Also, in
the QBE Query method, how would I reference my particular
function? Thanks in advance!
Not having any idea what your functions are intended to do nor what
inputs they require I can only be very general here!
You can put all the functions in one Module (or one in each module if
you prefer). Just remember that the function names and the module
names are from the same "namespace" - don't use the same name for a
function and for a module.
The syntax of a function declaration is
Public Function Functionname(arg1 AS datatype, ...) AS datatype
<zero to thousands of lines of VBA code>
<including somewhere...>
Functionname = <value to be returned>
....
End Function
In your query grid you would just type
SomeName: Functionname([fieldname], [fieldname]...)
.