K
Kimberly Anne
I'm trying to write a function that will count unique policy numbers.
For the first occurance of a policy number, the field polcnt is set to
1. For subsequent occurances, it is set to 0. I'm getting an error
that the query is too complex, and I have no idea why, as it isn't
really complex at all. The error is occuring when I get to the
rst.Update line. Any ideas as to what I'm doing wrong? Here is the
query:
Function PolicyCount()
Dim rst As New ADODB.Recordset
Dim dbCurrent As New ADODB.Connection
Set dbCurrent = CurrentProject.Connection
rst.CursorLocation = adUseClient
rst.Open "MVA4", dbCurrent, adOpenKeyset, adLockOptimistic
rst.Sort = "CONTRACTNO"
With rst
rst.MoveFirst
Do While Not .EOF
policy = rst.Fields("CONTRACTNO")
rst.MoveNext
polno = rst.Fields("CONTRACTNO")
rst.MovePrevious
If policy = polno Then
rst.Fields("polcnt") = 0
Else
rst.Fields("polcnt") = 1
End If
rst.Update
rst.MoveNext
Loop
End With
End Function
For the first occurance of a policy number, the field polcnt is set to
1. For subsequent occurances, it is set to 0. I'm getting an error
that the query is too complex, and I have no idea why, as it isn't
really complex at all. The error is occuring when I get to the
rst.Update line. Any ideas as to what I'm doing wrong? Here is the
query:
Function PolicyCount()
Dim rst As New ADODB.Recordset
Dim dbCurrent As New ADODB.Connection
Set dbCurrent = CurrentProject.Connection
rst.CursorLocation = adUseClient
rst.Open "MVA4", dbCurrent, adOpenKeyset, adLockOptimistic
rst.Sort = "CONTRACTNO"
With rst
rst.MoveFirst
Do While Not .EOF
policy = rst.Fields("CONTRACTNO")
rst.MoveNext
polno = rst.Fields("CONTRACTNO")
rst.MovePrevious
If policy = polno Then
rst.Fields("polcnt") = 0
Else
rst.Fields("polcnt") = 1
End If
rst.Update
rst.MoveNext
Loop
End With
End Function