Macro to Open Another Database (1 Viewer)

DBFIN

Registered User.
Local time
Yesterday, 23:10
Joined
May 10, 2007
Messages
205
I want to use a macro that simply opens another database. For example I want to run a macro from Database A to open Database B.
 

Rabbie

Super Moderator
Local time
Today, 04:10
Joined
Jul 10, 2007
Messages
5,906
See this thread. I think it should help you. Wonderful what you find if you search the Forums
 
M

Mike375

Guest
You can't open a specific .mdb file with a macro action. You either use code or even simpler is to run a batch file with the macro. A batch file is run from a macro with RunApp action line. The bottom of the macro screen is where you enter the location of the batch file as in:

To open the Access file called PriceList in folder letters this would be the batch file

\Letters\pricelist.mdb

If the batch file was called openaccess.bat and was on the C: drive then for RunApp

c:\openaccess.bat

One of the other blokes should be along and post up the code to open another db from your db. If you want to use a .bat file then let me know and I will show you how to make it, very easy.
 

DBFIN

Registered User.
Local time
Yesterday, 23:10
Joined
May 10, 2007
Messages
205
I reviewed the thread mentioned in Rabbie's reply. I created a button, selected category = application, selected action = run application, then browsed to the following path: D:\Retention\Coverage Update.mdb. The Coverage Update database is in the D:\Retention folder. When I use the button, I receive an "invalid argument" error message.
 

Rabbie

Super Moderator
Local time
Today, 04:10
Joined
Jul 10, 2007
Messages
5,906
I reviewed the thread mentioned in Rabbie's reply. I created a button, selected category = application, selected action = run application, then browsed to the following path: D:\Retention\Coverage Update.mdb. The Coverage Update database is in the D:\Retention folder. When I use the button, I receive an "invalid argument" error message.
I merely passed on the link because there was nothing to indicate it didn't work so sorry about that. See Mike's reply for some suggestions
 

DBFIN

Registered User.
Local time
Yesterday, 23:10
Joined
May 10, 2007
Messages
205
I created a bat file called D:\Retention\opendatabase.bat by renaming an excel file with a bat extension. I input the database path D:\Retention\Coverage Update.mdb in the bat file. I created a macro that uses the RunApp action and input D:\Retention\opendatabase.bat in the command line.

The macro runs, but the database doesn't open.
 
M

Mike375

Guest
Firstly, edit your .bat file to have Pause at the end. That will leave the DOS screen open and you see the reason for failure. Unlike code or macros .bat files will run to the end if there is a problem, no Halt or Debugs:D

With your path put inverted commas around D:\Retention\"Coverage Update".mdb. The same is required if folders/network names are split names. But I think "Coverage Update".mdb
 
M

Mike375

Guest
PS,

The other way which is good is just create a shortcut and move the icon to the tool bar at the bottom of the screen so it is always visible. The shortcut also allows you to go direct to a form, macro etc in the db. I use this for a couple of small dbs I have.

The advantage of the macro/bat is having it do other things before the db is opened

The only way I can do the hyperlink is in Form Design and Insert. That stick a label on the form that does look just like clicking on something on a website. But it brings up oen of those messages along the lines of..do you really want to open this, is it safe etc.
 

DBFIN

Registered User.
Local time
Yesterday, 23:10
Joined
May 10, 2007
Messages
205
Thanks Mike! I edited the bat file to include D:\Retention\"Coverage Update".mdb and the macro now works. One final question. I tried an alternative using a button with the following command after selecting application, run application.

MSACCESS.EXE D:\Retention\"Coverage Update".mdb

Your first solution definitely works, so if this alternative isn't simple, I'll probably need to close this inquiry.
 
M

Mike375

Guest
The code the button creates has not worked for me. I think it did though for Excel and Word.

But if it works for you it will, unlike the hyperlink or shortcut, allow you to do other things before the db opened.

And of course the button can also run the .bat file.

So you now have a couple of solutions which puts in front of when you started the thread:)
 

DBFIN

Registered User.
Local time
Yesterday, 23:10
Joined
May 10, 2007
Messages
205
Thanks for all your help. I'll be closing the thread. I always wanted to know what motivates scholars like yourself to provide so much help to others. Are you a good samaritan or are you employed by Microsoft or the World Forum. This question has always been nagging at me. Either way, I greatly appreciate your help. It's fantastic knowledge that you impart.
 

Mippo

New member
Local time
Today, 05:10
Joined
Apr 24, 2008
Messages
1
Hello all,
;) I had the same problem, and fixed in the following way, that seems much easier ;) :
in the action pane: RunApp
in the command line: msaccess "\\Cls135it\documents\DB\gestione miq"

:D notes:
- the exact filename to be open was: gestione miq.mdb
- it works even on the net, even with a space within the filename, thanks to the quotations and even without the file extentions !
- the application name is MSACCESS

:) ciao :)
:) Mippo :)
 

Users who are viewing this thread

Top Bottom