Runcode macro

Cobra

Registered User.
Local time
Today, 15:31
Joined
Dec 8, 2008
Messages
20
I've made an Autoexec macro, how do I actually get it to run code and where do I put the code? I'm really confused with the function name bit.
 
Here's a little primer I'm putting together, so you get to be the tester:

http://www.baldyweb.com/Function.htm

The argument in the macro would look like:

FunctionName()
 
What kind of code do you want it to run?

I wanted to run the code from one of the posters here:

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i


 
Use runCode action line in macro.

At the bottom of the screen goes FunctionName()

If you copy code from a post/Google it will often look like

FileCopy "C:\LettersCopy\0Letter1Mike.doc", "c:\Letters\0Letter1Mike.doc"

Or

Private Sub Command369_Click()
FileCopy "C:\LettersCopy\0Letter1Mike.doc", "c:\Letters\0Letter1Mike.doc"
End Sub

The above is being run from a button on a form.

You need to have the code in a module which in turn will mean a function name.

Here is exactly the same sort of thinh in a module

Public Function ToLaptopDell()

FileCopy "C:\ViperResides\Viper.mdb", "\\MikeLaptop\ViperDaily\" & Format([Forms]![CodeBUSystem]![Current6]) + ".mdb"

Forms!CodeBUSystem!TimeStart = 1
End Function

ToLaptopDell() would go in a macro or if it is called from within code the () are dropped.

Code you get from postings and Google will often have Me in it and for a module put full form name.
 
Right, that seems to work for simple code now, thank you. However, how can I get the code:

Dim i As Integer
For i = 1 To CommandBars.Count
CommandBars(i).Enabled = False
Next i

To work in my module?
 
I understand that, however when I type in the code which I linked earlier, it says "The expression you entered has a function name which Access cannot find."
 
What is the name of the function? What is the name of the module it is in? How are you calling it in the macro?
 
What is the name of the function? What is the name of the module it is in? How are you calling it in the macro?

The function is called "hidebars" the module is called "hidebars" and I am calling it in the macro by putting "hidebars()" in the function name.

Thanks for getting back to me on this issue
 
The function is called "hidebars" the module is called "hidebars"

Rename the module to something else!! hidebarsMOD or something.

A function AND module cannot have the same name.

JR
 
I guess I'm going to have to bold and underline this on my site: "make sure you don't name the module the same as the function". ;)
 
I think you are right Paul. Many overlook that tiny little detail. ;)
 
I tend to name my modules with the function name plus a couple of letters added.

Module are the odd man out in the sense that the name of the module is not used so it is easy to see why the module name is so often used given that forms, macros etc are used by their name.
 

Users who are viewing this thread

Back
Top Bottom