running code form a module on startup

suepowell

Registered User.
Local time
Today, 22:33
Joined
Mar 25, 2003
Messages
282
Hi,

I have had a good look round the posts, but can't find the answer to this.

I have a form I want to run from another database, which I call using the following code. This database is added as a reference.

Public Function Timing()

Call opentimingmain

End Function

I have this code stored in a module.

This works fine when I run it from inside the module.

What I want to do is run this code when I open access, without opening any other forms, / switchboards etc.

I have tried creating a macro called autoexec and using the runcode command with the function name timing() which I selected from the list it showed me, so spelling is correct.

When I try and run this macro the message
"The expression you entered has a function name that Microsoft Access can't find"

This is very confusing, as it showed me the name in the macro design screen.

can anyone suggest the reason. Although I have been programming in access for 4 or 5 years, I have never used macros, so don't quite know what I am doing here.

Is there another way of running code from a module on startup?

Thanks in anticipation.

Sue
 
Try using a sub rather than function ie:

Public Sub Timing()

Call opentimingmain

End Sub
 
I tried this first, but it didn't work, thats why I went to a function, but thanks for the suggestion.

Anyone have any more ideas?

Sue
 
Sue,

I copied the same moves you did and my AutoExec worked fine.

Made a test database, created a module, saved a function that opened a form "Form1", created a new macro using the RunCode command, selected the function name in my current database in the Action Arguments, named the macro AutoExec and when the database opened, my "Form1" form was displayed.

This is with Access 2003

I am not sure why it isn't working. You can call a sub from within a function, but that shouldn't make a difference... ??? It didn't here, tried it both ways.

???? Compact and Repair?

Look for spaces in your Function name in your Action Arguments after you made your selection, sometimes Access will insert spaces where it shouldn't etc.
 
Last edited:
Need the answer to a couple of specific questions:

Is the other DB you are trying to open on another machine?

If so, is the other machine WinXP?

Is YOUR system running WinXP?

If yes to either, have you installed Service Pack 2 on either?

If yes to all, you MIGHT be running into a security problem associated with remote execution on WinXP after SP 2 is installed.

You are right to use functions in your macro. Unless macros have changed, they want to get something back - and that spells 'function' if I recall correctly. Subs don't do this.
 
Sorry for bringing back an old post but this answered a very frustrating question for me and nobody had confirmed the solution had worked in the original thread.

Final solution was very simple really.

Compact and Repair worked. As soon as I had done this error no longer occoured.
 

Users who are viewing this thread

Back
Top Bottom