runtime error '7874

R

Robert H

In the query the following works fine.
SELECT cdd.[DeviceCode],cdd.[DeviceConfig] FROM cdd WHERE cdd."
"[DeviceCode]='Module 01';

But from VBA, the following returns "runtime error '7874"

Public Sub SeekCfg()

Dim strSQL As String

strSQL = "SELECT cdd.[DeviceCode],cdd.[DeviceConfig] FROM cdd WHERE
cdd." & _
"[DeviceCode]='Module 01';"

DoCmd.OpenQuery strSQL

Could some please square me away
 
D

Douglas J. Steele

You can't use SQL with the OpenQuery method: it's looking for the name of a
stored query.
 
R

Robert H

Ahh, thanks. The is there a way to run that SQL as a query from VBA?


You can't use SQL with the OpenQuery method: it's looking for the name of a
stored query.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)


In the query the following works fine.
SELECT cdd.[DeviceCode],cdd.[DeviceConfig] FROM cdd WHERE cdd."
"[DeviceCode]='Module 01';
But from VBA, the following returns "runtime error '7874"
Public Sub SeekCfg()
Dim strSQL As String
strSQL = "SELECT cdd.[DeviceCode],cdd.[DeviceConfig] FROM cdd WHERE
cdd." & _
"[DeviceCode]='Module 01';"
DoCmd.OpenQuery strSQL
Could some please square me away
 
D

Douglas J. Steele

Dim qdfCurr As DAO.QueryDef
Dim strSQL As String

strSQL = "SELECT cdd.[DeviceCode],cdd.[DeviceConfig] " & _
"FROM cdd WHERE cdd.[DeviceCode]='Module 01'"
On Error Resume Next
Set qdfCurr = CurrentDb.QueryDefs("TempQuery")
If Err.Number = 3265 Then ' 3265 is "Item not found in this collection."
Set qdfCurr = CurrentDb.CreateQueryDef("TempQuery")
End If
qdfCurr.SQL = strSQL
DoCmd.OpenQuery "TempQuery"


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Robert H said:
Ahh, thanks. The is there a way to run that SQL as a query from VBA?


You can't use SQL with the OpenQuery method: it's looking for the name of
a
stored query.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)


In the query the following works fine.
SELECT cdd.[DeviceCode],cdd.[DeviceConfig] FROM cdd WHERE cdd."
"[DeviceCode]='Module 01';
But from VBA, the following returns "runtime error '7874"
Public Sub SeekCfg()
Dim strSQL As String
strSQL = "SELECT cdd.[DeviceCode],cdd.[DeviceConfig] FROM cdd WHERE
cdd." & _
"[DeviceCode]='Module 01';"
DoCmd.OpenQuery strSQL
Could some please square me away
 

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