Hi Brian,
1. what a function is in access
Procedures include functions and subroutines. A function is a procedure that
can return a value, although it doesn't have to. Subroutines do not return a
value--they just do something. Procedures can be private or public. Private
procedures are "visible" to other procedures only within the same module.
2. an example of a function and how it is used. I guess Im asking how to
call a function.
In your previous post, with subject "populating file names and locations to
a table":
http://www.microsoft.com/office/com...a72556-1130-47ee-a014-22d0df0c2afe&sloc=en-us
the code you posted includes examples of calling functions. The first
example is found here:
lngflags = tscFNPathMustExist Or tscFNFileMustExist _
Or tscFNHideReadOnly
Three functions are called: tscFNPathMustExist, tscFNFileMustExist and
tscFNHideReadOnly. They apparently do not require any parameters. However,
since you did not post the code for these functions, none of us will really
know what the return values might be. If you click your mouse cursor into one
of these function names in your code, and then press the Shift and F2 keys at
the same time, you should find that focus is taken to the named function.
(You can use Ctrl Shift F2 to return to where you started).
The next example is found here:
varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngflags, _
strDialogTitle:="Please choose a file...")
Here, you are initializing the variant variable named "varFileName" with the
return value of a function named "tsGetFileFromUser" that is being called.
You are also supplying four parameters to this function, using named
arguments (ie. :=) in the process of calling it: fOpenFile, strFilter,
rlngflags and strDialogTitle. Since you did not include the code for
tsGetFileFromUser, we can only assume that it is working for you.
A very simple example would be the following function. Create a new module.
Copy and paste the following function into this new module:
Public Function MyFunction as String
dim intResponse as Integer
intResponse = Msgbox("Need any mind altering substances today?", _
vbQuestion + vbYesNo, "Don't worry...be happy!")
Select Case intResponse
Case vbYes
MyFunction = "Have a beer!"
Case vbNo
MyFunction = "You must be in a blissful state!"
Case Else
MyFunction = "Hmmm...You're hard to figure out!"
End Select
Debug.Print MyFunction
End Function
To run your new function, open the Immediate Window (Ctrl G). Type in the
following and press the Enter key:
MyFunction
My suggestion is to purchase a book that includes an introduction to writing
VBA code.
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________