访问VBA / SQL"运行时错误'':需要对象"

时间:2014-03-17 14:37:43

标签: sql vba

我继续得到“运行时错误'424':需要对象”,我不知道为什么,当我按下调试时,它会将我带到行qdf.SQL = strSQL并突出显示为黄色。我想知道是否有人知道这是什么问题?

Sub UpdateX()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

Set db = CurrentDb
Set rs = db.OpenRecordset("References")

strSQL = "SELECT References.DocNum, References.Availability " & _
     "FROM References " & _
     "WHERE References.Source = 'Book' " & _
     "ORDER BY References.DocNum;"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryTest"
End Sub

由于

2 个答案:

答案 0 :(得分:1)

qdfNothong(null)。您需要将qdf设置为某个内容。

答案 1 :(得分:0)

试试这个 strSQL = "SELECT References.DocNum, References.Availability FROM References WHERE References.Source = 'Book' ORDER BY References.DocNum;" Set rs = CurrentDb.OpenRecordset(strSQL) Do until rs.EOF
    ' str2 =基于rs更新查询     DoCmd.RunSQL STR2 rs.MoveNext Loop rs.Close