Not entirely sure how to fix this code that is giving me a run-time error 3021: No Current Record.
The purpose is to click this button and it will populate a few text boxes with the results of the first record of the query. It is then supposed to populate another two text boxes with the next record of results from the query using the MoveNext.
Private Sub btnSCC07_Click()
Dim dbs As DAO.Database
Dim rsTable As DAO.Recordset
Dim rsQuery As DAO.Recordset
Set dbs = CurrentDb
Set rsQuery = dbs.OpenRecordset("SELECT * FROM qrySccS2 WHERE PAYORNAME = 'Medicaid' AND OVERRIDECODESALL = 7", dbOpenDynaset)
rsQuery.FindFirst ("[PAYORNAME]='Medicaid'")
num1 = rsQuery!PAYPLANNAME
num2 = rsQuery!Count
txtMedicaid9 = num1
txtMedicaidCount9 = num2
Debug.Print (txtMedicaid9)
rsQuery.MoveNext
Debug.Print ("Test")
num3 = rsQuery!PAYPLANNAME
num4 = rsQuery!Count
txtMedicaid10 = num3
txtMedicaidCount10 = num4
rsQuery.Close
Set rsQuery = Nothing
So the first section works, but it's when it reaches the line num3 = rsQuery!PAYPLANNAME is where it throws the error. Thank you in advance for any insight you may be able to provide.
rsQuery.MoveLast rsQuery.MoveFirst
to force the count. Why do you have a MoveNext without a loop? – June7rsQuery.MoveLast
andrsQuery.MoveFirst
right after theSet rsQuery = dbs.OpenRecordset
line and it is still return 1 in the immediate window and throwing the error. – N.Ha