Solved

Changing database

Posted on 1999-01-25
7
597 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
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.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

828 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