Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening a new another data base 1

Status
Not open for further replies.

notreconised

Technical User
Jul 21, 2002
14
GB
HI
can any one help me i wish to open another database With comand button (BY code) but i do not wish to close current data base.

Many thanks in advance
 
What do you wish to do with the other not database, I imagine, but another table from the current database.

to do so you,

DIM db as doa.database, rs as doa.recordset

set db = currentdb() ' or another if you wish
set rs = db.openrecordset("Table") or

set rs = db.openrecordset("SELECT * FROM 'TABLE';")


It is now open for what you wish to do.

Did you really mean to open another form?

if so:


DOCMD.openform "frmName"


rollie@bwsys.net
 
Use the shell command -

lngResult = Shell("C:\MSAccess.exe yourdatabasepath.mdb")

Replace C:\MSAccess.exe with the path to Microsoft Access on your computer.
 
Hi notreconised,

You need to create a new workspace to open a second database in Access, something like ...

Code:
Dim tjWorkspace As DAO.Workspace
Dim tjDatabase As DAO.Database
Dim tjRecordset As DAO.Recordset

Set tjWorkspace = CreateWorkspace("Tony", "admin", "")
Set tjDatabase = tjWorkspace.OpenDatabase("D:\My Documents\MyDatabaseName")

Set tjRecordset = tjDatabase.OpenRecordset("TableName", dbOpenDynaset)
Code:
' Do what you want with the recordset or anything else in the database
Code:
tjRecordset.Close
tjDatabase.Close
tjWorkspace.Close

Set tjRecordset = Nothing
Set tjDatabase = Nothing
Set tjWorkspace = Nothing

Enjoy,
Tony
 
If it is an Access database you can reference directly in the select statement. There are different ways. Here is one example using ADO.

Dim sql1 As String, exterDB As String
Dim rs As New ADODB.Recordset
Dim cn As New ADODB.Connection
Set cn = CurrentProject.Connection

exterDB = "C:\AEmptyDir\employee.mdb"

sql1 = "select * from employees IN '" & exterDB & "';"

rs.Open sql1, cn, adOpenStatic, adLockOptimistic
Debug.Print "rs = "; rs(0); " "; rs(1)



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top