Solved

Changing database

Posted on 1999-01-25
7
567 Views
Last Modified: 2012-05-04
I am trying to close one database and open another.

Why doesn't this work?

 Public Sub Vermilion()
 Application.CloseCurrentDatabase
 Application.NewCurrentDatabase "c:\acadiana\vermilion   parish directory.mdb"
 DoCmd.RunCommand acCmdOpenDatabase
 End Sub

The current dara base closes OK, but then nothing. BTW the path is correct.

Thanks.
 
0
Comment
Question by:instanet
7 Comments
 
LVL 7

Expert Comment

by:Dedushka
Comment Utility
Hi, instanet!

If you use the CloseCurrentDatabase method to close the database that is open in the current instance of Microsoft Access, you can then open a different database without having to create another instance of Microsoft Access.

You can use the NewCurrentDatabase method to create a new database in the Microsoft Access window, so use the OpenCurrentDatabase method to open an existing database as the current database.

Public Sub Vermilion()
 Application.CloseCurrentDatabase
 Application.OpenCurrentDatabase "c:\acadiana\vermilion   parish directory.mdb"
End Sub

Regards,
Dedushka
0
 

Author Comment

by:instanet
Comment Utility
This still doesn't work!
Is there an alternative? a Macro of some sort?
Thanks this is the code I used that bombed. I tried with and without brackets around the path string.

Public Sub Vermilion()
    Application.CloseCurrentDatabase
    Application.OpenCurrentDatabase "C:\Acadiana (New)\Vermilion Parish Directory.mdb"
End Sub
0
 
LVL 7

Expert Comment

by:smilitaru
Comment Utility
Hello
What you want is not possible, because when you close current database the execution of code are suspended. So, CloseCurrentDataBase is the last line that are executed.
OpenCurrentDatabase, and NewCurrentDatabase are methodes that are using just with OLE tehnique, that means you open another session of Access and to this session you give commands for open a existing or a new database.
For conclusion when you use CloseCurrentDatabase, this is the last line that executing

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:instanet
Comment Utility
There has to be an easy way to change databases. Just like what happens when you click on File/Open and select a file: Access stays open, the database closes and the new one opens.

How do I do that in code?
0
 
LVL 7

Expert Comment

by:smilitaru
Comment Utility
Ok.
Wait for the desired answer.
If you don't receive I have a workaround for this problem, but is not so simple.

0
 
LVL 10

Accepted Solution

by:
brewdog earned 50 total points
Comment Utility
Access doesn't really provide an easy way to do that through code. You could do this:

    Dim varApp as variant
    varApp = Shell("path to your database")
    DoCmd.Quit

You could also set up a hyperlink directly to the database and then code the On_Click event to DoCmd.Quit.

Those are the only ways I know to do it . . .

brewdog

0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
GREETINGS!

This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.  Also in the Community Support link is a question on how experts can help, if they wish, on the cleaning of old and abandoned questions.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now