运行时错误3021-没有当前记录 [英] Run time error 3021- no current record
问题描述
我想将查询结果链接到文本框,但出现此错误:这是我的代码:
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 XValue, YValue,Wert FROM tb_DCM_Daten WHERE (FzgID=" & Forms!frm_fahrzeug!ID & " AND Name='" & List2.Value & "')")
Text10.Text = rst!XValue //error in this line
应该返回大约20条记录
It should be return c.a 20 record
为什么会出现此错误,我该如何解决?
Why do I get this error and how can I solve it?
推荐答案
出现此错误的一个可能原因是Name
是Access中的保留字,因此您应该使用
One possible reason for the error is that Name
is a reserved word in Access, so you should use
... & " AND [Name]='" & ...
您还可以在尝试使用rst!XValue
之前测试rst.EOF
.也就是说,要验证您的查询是否返回至少一行,您可以添加代码
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
立即在.OpenRecordset
调用之后.如果Recordset 为空,则需要验证@GregHNZ在上面的注释中所述的SQL语句.
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.
这篇关于运行时错误3021-没有当前记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!