sherlocked
Registered User.
- Local time
- Yesterday, 19:30
- Joined
- Sep 22, 2014
- Messages
- 125
Hello Experts,
I have the below function passing a value to a variable that is used to populate an unbound text field on a report. For some reason, the result I'm getting is "1" instead of the expected number. It seems the function is only counting the first record in the recordset.
Any idea on why, and what can be done?
I have also tried this as IDJan = rst!CountofID but get an error when there are no records in the recordset.
Thank you in advance! My code:
I have the below function passing a value to a variable that is used to populate an unbound text field on a report. For some reason, the result I'm getting is "1" instead of the expected number. It seems the function is only counting the first record in the recordset.
Any idea on why, and what can be done?
I have also tried this as IDJan = rst!CountofID but get an error when there are no records in the recordset.
Thank you in advance! My code:
Code:
Public Function GetIdentity()
Dim rst As Recordset
Dim IDJan as Integer
Set rst = CurrentDb.OpenRecordset("SELECT Count(tblRecords.ID) AS CountOfID " _
& "FROM tblRecords " _
& "GROUP BY tblRecords.ExecYear, tblRecords.ExecMonth, tblRecords.FraudType " _
& "HAVING tblRecords.ExecYear='" & Form_frmMain.cmboYear & "' AND tblRecords.ExecMonth='1' AND tblRecords.FraudType='Identity'")
IDJan = rst.RecordCount
rst.Close
Set rst = Nothing
End Function