Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Changing database

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
instanet
Asked:
instanet
1 Solution
 
DedushkaCommented:
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
 
instanetAuthor Commented:
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
 
smilitaruCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
instanetAuthor Commented:
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
 
smilitaruCommented:
Ok.
Wait for the desired answer.
If you don't receive I have a workaround for this problem, but is not so simple.

0
 
brewdogCommented:
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
 
MoondancerCommented:
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now