OpenDatabase

R

rodneykocot

How can I get the OpenDatabase method to work? I have
tried to use OpenDatabase to open a database on a
different drive (H:) than the drive that the CurrentDB
(C:) is on. I have attempted this several times in
Access97, Access2000, ... and can not get it to work.
Please Help, sample attempts follow:


Dim wsp As Workspace
Dim AuditDB As Database
Set wsp = DBEngine.Workspaces(0)
AuditDBFileName = CStr(InAS400SystemAudits
("databasefilename"))

'Set AuditDB = Workspaces(0).OpenDatabase
(AuditDBFileName)
'Set AuditDB = DBEngine.Workspaces(0).OpenDatabase
(AuditDBFileName)
'Set AuditDB = OpenDatabase(AuditDBFileName)
Set AuditDB = wsp.OpenDatabase(AuditDBFileName)


The error is "Invalid procedure call or argument" Error
#5. I have duplicated the code in the help examples and
still get the same error.
 
G

Graeme Richardson

What is the string returned by
CStr(InAS400SystemAudits("databasefilename"))?

Also, try explicitly declaring your variables as DAO (adding Microsoft DAO
.... reference as required):

Dim wsp As DAO.Workspace
Dim AuditDB As DAO.Database
Dim AuditDBFileName As String
AuditDBFileName = CStr(InAS400SystemAudits("databasefilename"))
Set wsp = DBEngine.Workspaces(0)
Set AuditDB = wsp.OpenDatabase(AuditDBFileName)




Alternatively, are you trying to do this (place code in new module):
Private mappAccess As Access.Application
Public Sub OpenDb()
Set mappAccess = New Access.Application
mappAccess.OpenCurrentDatabase "C:\Temp\db1.mdb"
mappAccess.Visible = True
End Function
Public Sub CloseDb()
'mappAccess.CloseCurrentDatabase
Set mappAccess = Nothing
End Function
 
D

david epsom dot com dot au

These are DAO calls. You need to reference the DAO library,
and you should preface the declarations (and, optionally, the
calls).

dim wsp as dao.workspace
set auditdb = dao.opendatabase

(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top