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
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.