Open Access Form from Excel Macro

D

dl

I've researched strategies for this for the last couple days and the usual
method seems to be many lines of vb, which in my situation didn't seem to
keep the form open or just didn't work. It would open the db and the form,
but they would then close immediately. The solution I ended up using
couldn't be simpler.

Sub whatever()

Dim RUN_IT

'''Opens Access exe file, then your DB, then the macro that will open the
form, with visible argument=1, which keeps it open'''

RUN_IT = Shell("""C:\Program Files\Access 2000\Office\msaccess.exe""
""C:\DatabaseWithMacroToOpenForm.mdb"" /x ""name of the macro""", 1)

End Sub

The magic is that ", 1" at the end of the Shell command which tells Access
to stay open. A zero there would cause it to close after the macro was run.

All you have to do is then put a command button on the form that when
clicked closes the Form and the Macro, followed by a Quit / SaveAll step.

Note: You may know this, but if you don't include a quit step at the end of
the macro an instance of MSACCESS.exe will stay running in the background
(only seen in task manager) which leaves an entry in the ldb file causing the
db to stay locked.

Btw, killing the extra MSACCESS.exe in task manager that results from a db
closing unexpectedly, which leaves the ldb file and won't allow you to have
exclusive access -killing that will free it up again. Just figured that out
the other day. Used to have to copy it /rename it before I found that.

I just wanted to share since I've found so much value in all the information
everyone on this group supplies. Thank you all. Hope this is helpful to
someone.
 

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