Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

It should be return c.a 20 record

Why do I get this error and how can I solve it?

like image 524
Kaja Avatar asked Jun 27 '13 06:06

Kaja


People also ask

How do you fix run time error 3021?

Rearrange your code so your SQL Statement is in a string variable, and print it out to the immediate window. That way you'll see if there's anything wrong with it. If nothing obvious, that the output SQL and put it in a query and verify that there is a record that matches your criteria.

What is Run Time Error 3021?

"Run-time error '3021' No current record"This error occurs when attempting to change the shared SysData folder location from the Admin/Organization screen.


2 Answers

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.

like image 59
Gord Thompson Avatar answered Oct 10 '22 21:10

Gord Thompson


Usually, I would do this. Create a new query in Access , switch to SQL View , Paste my code there and go to Design >> Run.

SELECT XValue, YValue,Wert FROM [tb_DCM_Daten] WHERE [FzgID]=12 AND [Name]='ABC';

if your query syntax is correct you should see the result otherwise error mssg will tell where you are wrong. I used to debug a much more complicated query than yours and this is the way that I've done. If there is still error, maybe you should try

Dim sql as String
sql = "SELECT...."
Set rst = CurrentDb.OpenRecordset(sql)

Another possible reason might be your table name. I just wonder what is your table name exactly ? if your table contains white space you should make it like this [DCM Daten].

like image 27
Nexus Avatar answered Oct 10 '22 21:10

Nexus