JavaEar 专注于收集分享传播有价值的技术资料

Access VBA/SQL "Run-Time error '424': Object required"

I keep on getting getting a "Run-Time error '424': Object required" and I am not sure why, when I press debug it takes me to the line qdf.SQL = strSQL and highlights it yellow. I was wondering if anybody knows what is the problem?

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

Thanks

2个回答

    最佳答案
  1. qdf is Nothong (null). You need to set qdf to something.

  2. 参考答案2
  3. Try this 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 = Update query based upon rs DoCmd.RunSQL STR2 rs.MoveNext Loop rs.Close