>> Open other db with vba without running Autoexec

G

Guest

Hi, I want to use vba to open another database. When I do, the autoexec in
the other database is triggered.

How can I open this other database without running the autoexec in the other
database?

Any ideas or suggestions appreciated :)

Many thanks
Jonathan
 
B

Brendan Reynolds

I don't think you can. There is, however, something that you can do to make
your Access apps automation-friendly. Your start-up code can test the
Application.UserControl property, and execute its usual startup code only if
the property returns True.

For example, create an MDB with an AutoExec macro that uses the RunCode
action to call the following function ...

Public Function StartupFunction()

If Application.UserControl Then
MsgBox "Hi there, user!"
End If

End Function

When you open this MDB normally, without using automation, you'll see the
message box. Now open the same MDB via automation ...

Option Compare Database
Option Explicit

Private mobjApp As Access.Application

Public Sub TestAuto()

Set mobjApp = New Access.Application
mobjApp.OpenCurrentDatabase ("c:\usenet\autotarget.mdb")
mobjApp.Visible = True

End Sub

Notice that the message box is not shown.
 
G

Guest

Hi, Jonathan.
How can I open this other database without running the autoexec in the other
database?

If the AllowBypass Key hasn't been disabled, then you can use the Windows
API to programmatically press the <SHIFT> key. Use the code on the following
Web page:

http://www.mvps.org/access/api/api0068.htm

Within the fGetRefNoAutoexec( ) function, you can write your code that you
need to automate the remote database, or even call your local procedure to
run right after the remote database is opened. For example:

' Open a mdb with Autoexec
Call .OpenCurrentDatabase(strMDBPath, False)

' Do whatever in this section to automate remote DB.
Call mySub

' Revert back keyboard state
Call SetKeyboardState(abytCodesSrc(0))

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact info.
 

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

Top