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!

Calling all functions 1

Status
Not open for further replies.

rry2k

Programmer
Jun 28, 2001
678
US
Hi,

I have created a function in a Module that I would like to run from a Macro. Can someone tell me how to have it autorun once I do a button click to call the macro? I seem to remember something about naming the Module a certain way like autoexec but I'm not sure.

Thanks..Russ
 
Autokeys is used to set up functionkey or other "hot" keys, which I don't think is what you want.

You can "call" a function simply by it's name, so a command button would just need:

Sub Button1_Click()
Call MyFunction(...)
End sub

To run it from a macro, use the RunCODE action, and place the function name in the command box down at the bottom that says "Function Name"




78.5% of all statistics are made up on the spot.
Another free Access forum:
More Access stuff at
 
Thanks. Now another quick question. I have an sql string in my code that I need to add a where clause to. I'm getting hung up on the syntax(probably wrong quotes). here is what I have now:

SQLStatement:="SELECT * FROM [Table1]" & "Where Table1.EmpLastName = " _
"cmbEmpList.Value" & ';'

Thanks for the help..Russ
 
Try this

strSQLStatement = "SELECT * FROM [Table1]" & " Where Table1.EmpLastName = " & cmbEmpList.Value & "';'"
 
Thanks,

I'll give that a shot as soon as I can get in.
I'm caught in a loop right now between Access and word.
I think my Macro is executing automatically as well as the one in word. Is there a way to break in as soon as I try to open the db? ctrl+break doesn't work.

Tahnks..Russ
 
When calling functions you would normally assign the result of the function to a variable that is the same type as the return from the function.

Public Function HelloWorld() As String
HelloWorld = "Hello World!"
End Function

'Results of the debug session
?HelloWorld
Hello World!
Call HelloWorld


'In code
Dim strReturn As String
strReturn = HelloWorld()
'Hello World! is stored in the variable

'When running a subroutine with one parameter
YourSub

'When running a subroutine with > one parameter
Call YourSub

These can all be code behind the button, generally in the Click event.

Steve King

Growth follows a healthy professional curiosity
 
When calling functions you would normally assign the result of the function to a variable

Good point Steve - I missed that one..I have a lot of functions that don't return values, they just do stuff and come back..which makes them more like procedures, so I am more used to writing

...
Call Foo()
Call Fie()
Call Fum()
...

Star4U

78.5% of all statistics are made up on the spot.
Another free Access forum:
More Access stuff at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top