Can't Find Query Error

R

Rosco

Can someone see my error in the following code. I get an "Access can't see query error on the OpenQuery command.
The query is built in the proper place, however.

Function RunQuery()
Dim wrkJet As Workspace, dbBackEnd As Database, qd As QueryDef, strPath As String, strFileNme As String
Dim sqlString As String

'DoCmd.SetWarnings False

strPath = "H:\Development\FolderName\"
strFileNme = "File_BE.mdb"

sqlString = "some sql to make table query string "

Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)
Set dbBackEnd = wrkJet.OpenDatabase(strPath & strFileNme)

With dbBackEnd
Set qd = .CreateQueryDef("qryQueryName", sqlString)
DoCmd.OpenQuery "qryQueryName", acViewNormal, acEdit
.QueryDefs.Delete qd.Name
End With

'DoCmd.SetWarnings True
End Function

Thanks for the Help
Rosco
 
V

Van T. Dinh

Try adding:

DoEvents

once or twice after the statement "Set qd ..." and before the
"DoCmd.OpenQuery ..."

--
HTH
Van T. Dinh
MVP (Access)


Rosco said:
Can someone see my error in the following code. I get an "Access can't see
query error on the OpenQuery command.
The query is built in the proper place, however.

Function RunQuery()
Dim wrkJet As Workspace, dbBackEnd As Database, qd As QueryDef, strPath
As String, strFileNme As String
 
R

Rosco

No soap, Van. Still getting the "Can't find the object" error
Thanks for trying, any other suggestions
Rosc
 
V

Van T. Dinh

Just realised that you created the query in the Back-End and the
DoCmd.OpenQuery will only look for the Query in the Front-End.
 
R

Rosco

So, how can I run a query on the back end, from the front end. I am trying to update a table on the back end as part of a start up routine. The query grabs data from an AS400 table, and I do not want to give the users direct access to the AS400 table in question
Thanks
 
V

Van T. Dinh

Don't need to create (and delete) QueryDef in this case. Use:

.Execute sqlString
 

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