I am trying to run a procedure in another access database. I have the following code in the "active" database. The query and "PopBucket" procedures are in the "other" database. I got it to work - but would like to understand why the changes I've made have caused it not to work.
I got this to work this way: (very abbreviated)
Private Sub cmdRuntblBuildQuery_Click()
dim appAccess as New Access.Application
strFile as String
strFile = "C\filelocation"
appAccess.OpenCurrentDatabase strFile
appAccess.Visible = True
appAccess.Docmd.OpenQuery "qryMkTbl"
Call PopBucket(strFile)
rest of code
appAccess.close
appAccess = Nothing
Public Sub PopBucket(strFile)
Dim db as as Database
Dim rst as Recordset
Set db = DBEngine(0).OpenDatabase(strFile)
Set rst = db.OpenRecordset("tbl",dbOpenDynaset)
rest of code
Since I had to use the OpenDatabase method to get the PopBucket procedure to work, I decided to do the same with the first procedure - so I changed it as follows:
Private Sub cmdRuntblBuildQuery_Click()
Dim db as Database
Dim strFile as String
strFile = "C\filelocation"
Set db = DBEngine(0).OpenDatabase(strFile)
db.Docmd.openquery "qryMkTbl"
Call PopBucket(strFile)
When I compile I get "Method or data member not found" and the db.Docmd.openquery is highlighted. I know I have to refer to the database because if I remove the "db" in front of the DoCmd access says it can't find the query.
Question: Why does this "opendatabase" work in one procedure and not in the other? Thanks for your thoughts. Marie
I got this to work this way: (very abbreviated)
Private Sub cmdRuntblBuildQuery_Click()
dim appAccess as New Access.Application
strFile as String
strFile = "C\filelocation"
appAccess.OpenCurrentDatabase strFile
appAccess.Visible = True
appAccess.Docmd.OpenQuery "qryMkTbl"
Call PopBucket(strFile)
rest of code
appAccess.close
appAccess = Nothing
Public Sub PopBucket(strFile)
Dim db as as Database
Dim rst as Recordset
Set db = DBEngine(0).OpenDatabase(strFile)
Set rst = db.OpenRecordset("tbl",dbOpenDynaset)
rest of code
Since I had to use the OpenDatabase method to get the PopBucket procedure to work, I decided to do the same with the first procedure - so I changed it as follows:
Private Sub cmdRuntblBuildQuery_Click()
Dim db as Database
Dim strFile as String
strFile = "C\filelocation"
Set db = DBEngine(0).OpenDatabase(strFile)
db.Docmd.openquery "qryMkTbl"
Call PopBucket(strFile)
When I compile I get "Method or data member not found" and the db.Docmd.openquery is highlighted. I know I have to refer to the database because if I remove the "db" in front of the DoCmd access says it can't find the query.
Question: Why does this "opendatabase" work in one procedure and not in the other? Thanks for your thoughts. Marie