Have a data entry form, where Certificate_No is based on School, and the last number used.
A SQL statement:
sSQL = "SELECT TOP 1 Exam.School, Exam.Certificate_No as LN FROM Exam WHERE Exam.School = S ORDER BY Exam.Certificate_No DESC;"
Based on entering the School number (S), works in Query.
In vba I have this:
Dim db As DAO.Database
Set db = CurrentDb()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset(sSQL)
sSQL = "SELECT TOP 1 Exam.School, Exam.Certificate_No as LN FROM Exam WHERE Exam.School = S ORDER BY Exam.Certificate_No DESC;"
But keep getting an error at Set rs....
Once I am able to read the LastNumber I can increment the next number.
Second part
I am using AfterUpdate successfully for copying dates down to the next record. Will this work for the above SQL, once working?
The AfterUpdate is :
Private Sub Exam_Date_AfterUpdate()
Me.Exam_Date.DefaultValue = """" & Me.Exam_Date.Value & """"
End Sub
Thanks
Additional Info: 7/1 1500 EDT
BTW, DMAX will only work if you can run a query on the Exam database to optain all Cert no's for a given school, which is why I'm trying to get the SQL statement to work.
Cert no's are formatted as School-NO-5 digits, or 100-12345 as a string. If I find the last number for school 100 is 100-22222, I can use right(Certificate_no,5) to an integer, again, add 1 and recombine into 100-22223 as a string.
But can't do this automatically if I can't get SQL statement to work. Manually, if I type a new cert no into the certificate_no field during an insert (via a form), I can get the next record to increment, but not the third or additional records automatically.
Conclusion
I asked this question a different way see New Question and was able to find an answer that works.