Solved

Changing database

Posted on 1999-01-25
7
589 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
ID: 1977721
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
ID: 1977722
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
ID: 1977723
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
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)

 

Author Comment

by:instanet
ID: 1977724
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
ID: 1977725
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
ID: 1977726
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
ID: 6875484
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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.

773 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