sherlocked
Registered User.
- Local time
- Yesterday, 19:53
- Joined
- Sep 22, 2014
- Messages
- 125
Hello Experts,
I'm attempting to get the average of a field in a recordset that groups results by year. Code is below. I am getting a "the field is not large enough for the data you attempted to paste" error and can't figure out why. Any ideas on what I'm doing wrong?
I'm attempting to get the average of a field in a recordset that groups results by year. Code is below. I am getting a "the field is not large enough for the data you attempted to paste" error and can't figure out why. Any ideas on what I'm doing wrong?
Code:
Public Function GetAgencyHistory()
Dim AgencyHis1 as Double
Dim ThisYear As Integer
Dim rst As Recordset
Dim sql As String
ThisYear = DatePart("yyyy", Date)
sql = "SELECT Count(tblRecords.ID) AS CountOfID " _
& "FROM tblRecords " _
& "GROUP BY tblRecords.ExecYear, tblRecords.ExecMonth, tblRecords.FraudReason, tblRecords.Agency " _
& "HAVING tblRecords.[ExecMonth] = " & Forms!frmMain.cmboMonth & " AND " _
& "tblRecords.[ExecYear] <> " & ThisYear & " AND " _
& "tblRecords.[FraudReason]= 'Impostor - Living ID (Suspect Alien)' AND " _
& "tblRecords.[Agency] = '" & Forms!frmMain.cmboAgency & "' "
With CurrentDb.OpenRecordset(sql)
If Not .EOF Then
AgencyHis1 = DAvg("CountOfID", sql)
.Close
End If
End With
End Function