Run time error 3021- no current record

后端 未结 4 1926
天命终不由人
天命终不由人 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:35

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

    0 讨论(0)
  • 2021-01-13 01:53

    After trying the solutions above to no avail, I found another solution: Yes/No fields in Access tables cannot be Null (See allenbrowne.com/bug-14)

    Although my situation was slightly different in that I only got the "No current record." error when running my query using GROUPBY, my query worked after temporary eliminating the Yes/No field.

    However, my Yes/No field surprisingly did not contain any Nulls. But, troubleshooting led me to find an associated error that was indeed populating my query result with Null Yes/No values. Fixing that associated error eliminated the Null Yes/No values in my results, thus eliminating this error.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-13 01:55

    One more thing I like to add that may cause this, is your returning a sets of resultset that has "Reserved word" fields, for example:

    Your "Customers" table has field name like the following:

    Custnum  | Date | Custname
    

    we know that Date field is a reserved word for most database

    so when you get the records using

    SELECT * FROM Customers
    

    this will possible return "No Current Record", so instead selecting all fields for that table, just minimize your field selection like this:

    SELECT custnum, custname FROM Customers
    
    0 讨论(0)
提交回复
热议问题