Query is too complex?

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
 
V

Van T. Dinh

What is "MVA4"? If it is a Query, please post the SQL of the Query and
state the relevant relationships & data types of the Field.
 
K

Kimberly Anne

"MVA4" is the table that holds the data I'm wanting to sort. It has
7374 records, each record has 30 fields (about 10 strings and 20 or so
numeric).
 
V

Van T. Dinh

I am not sure what's wrong with the code but try using an SQL based on the
Table "MVA4" with ORDER BY clause to open the Recordset rather than using
the Sort Property of the Recordset.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top