Functions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone define:

1. what a function is in access

2. an example of a function and how it is used. I guess Im asking how to
call a function.

Or point me in the right directions to learn how functions are used withing
access.

Thanks, hope its not to stupid of a question.
 
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
__________________________________________
 
I think tscFNPathMustExist etc are probably Constants used in a Customized
FileDialog Function in this case (tsGetFileFromUser).
There are a lot of usefull Functions to be found at
http://www.mvps.org/access & many, many other places

HTH

Pieter
 
Thanks guy, Another words I have been using functions all along. Im just
strugling in writing code some time. However, once you figured it out you
never seem to forget it. For example if I forget a piece of code I go to a
previous database or a sample database or even this form and figure out how
the code works and how to apply in my databases. Im just assuming we all
learn that way. Thanks, you guys have been a great help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top