runtime error '7874

  • Thread starter Thread starter Robert H
  • Start date Start date
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
 
You can't use SQL with the OpenQuery method: it's looking for the name of a
stored query.
 
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
 
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
 
Back
Top