Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open;CloseCurrentDatabase

Posted on 1998-03-30
10
Medium Priority
?
497 Views
Last Modified: 2008-02-01
Hi,
How can i close the current database and open another one in the same window? i have tried using opencurrentdatabase and closecurrentdatabase but i just can't seem to get it. Any help would be great.
0
Comment
Question by:Jambyte
[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
10 Comments
 
LVL 17

Expert Comment

by:ramrom
ID: 1972483
Help says:
"You can use the OpenCurrentDatabase method to open an existing database as the current database. You can use this method to open a database from another application that is controlling Microsoft Access through Automation, formerly called OLE Automation. For example, you can use the OpenCurrentDatabase method from Microsoft Excel to open the Northwind sample database in the Microsoft Access window."
The key thing here that this method works when you are controlling Access from another application. It sounds like you want the access session itself to close one database and open another.

One way to do what you want is:

Sub Switch_To(new_mdb)
  SendKeys "%{f}c%{f}o" & new_mdb & ".mdb{enter}"
End Sub

Call this sub with the name of the .meb file you want to open, e.g. Switch_To "sales"

0
 
LVL 2

Author Comment

by:Jambyte
ID: 1972484
I would rather not use sendkeys, its kind of slopy, do you know of another way?
0
 
LVL 17

Expert Comment

by:ramrom
ID: 1972485
Sloppy? what does that mean? IF it works, why not use it?

I know of no other way within access. Consider that access is only functional when an mdb file is open in it. There is very little that can be done with no mdb open. The only way I know is to use sendkeys as illustrated or some other 3rd party macro player such as tempo.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Author Comment

by:Jambyte
ID: 1972486
is there a way to open a new database in a new window and then close the current database and window? programicaly? (w/o sendkeys)
0
 
LVL 17

Expert Comment

by:ramrom
ID: 1972487
Sub OpenDB(path) ' your pathname may vary
  Shell pathname:="c:\office97\office\msaccess.exe" & " " & _
  Chr(34) & path & Chr(34), windowstyle:=1
  Application.Quit
End Sub

Sub test()
  OpenDB "c:\foo\bar.mdb"
End Sub

0
 
LVL 12

Expert Comment

by:Trygve
ID: 1972488
ramrom: I don't think Jambyte ment to offend you in any way. Sendkeys are sloppy programming because it makes your code depend on the user not touching the computer till the keys has done their job. My experience is that a lot of users get impatient and start cliking and typing "to see what happened" if the program does not appear to do anything. This could make the keys getting sent to the wrong destination (speaking from experience).

There is almost always a way around using the sendkeys approach; docmd domenuitem ... and in Access'97 docmd.runcommand ... But sometimes there is no way around and then we have to cross our fingers and hope that the user does not manage to interfer with the process.

Have a nice day !
0
 
LVL 2

Author Comment

by:Jambyte
ID: 1972489
any other way?
0
 
LVL 9

Expert Comment

by:perove
ID: 1972490
Jambyte,
Somtimes ago i had the same problem. I worked a lot on it.And the only way I found was to use sendkeys.
perove
0
 

Accepted Solution

by:
jtb earned 0 total points
ID: 1972491
Have you tried this?

Dim acc As Object
Set acc = CreateObject("Access.Application.7")
acc.OpenCurrentDatabase "C:\MYDB.MDB"
Stop

Now your database is open, have a look.  If you want it to stay open, you should open a form or something.

acc.Docmd.openform "Formname"

Hope this helps,
jtb
0
 
LVL 1

Expert Comment

by:kodiakbear
ID: 6858511
Fixed the -1 problem on this question.
Escrow points corrected.

kb
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
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…

609 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