Run time error 3021- no current record

后端 未结 4 1958
天命终不由人
天命终不由人 2021-01-13 01:11

I want to link the result of a query to a Textbox but I get this error: here is my code:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(\"SELECT         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-13 01:54

    One possible reason for the error is that Name is a reserved word in Access, so you should use

    ... & " AND [Name]='" & ...
    

    You could also test for rst.EOF before trying to use rst!XValue. That is, to verify whether or not your query is returning at least one row you can add the code

    If rst.EOF Then
        MsgBox "The Recordset is empty."
    End If
    

    immediately after the .OpenRecordset call. If the Recordset is empty, then you'll need to verify your SQL statement as described by @GregHNZ in his comment above.

提交回复
热议问题