Solved

Changing database

Posted on 1999-01-25
7
608 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
My Do While is Not Producing Anything 15 88
Access Need to add combo box to sub form 10 52
Converting Access 2016 from 32-bit to 64-bit 8 63
Tabbed form question 5 21
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 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