ADO Sort Property

G

Greg Horwood

I have the following sample code which returns a run-time error 3251.

Private Sub btnMain_Click()
Dim rst1 As Recordset

Set rst1 = New ADODB.Recordset
rst1.CursorType = adOpenKeyset
rst1.LockType = adLockOptimistic
rst1.CursorLocation = adUseServer

rst1.Open "tblMain", CurrentProject.Connection
rst1.Sort = "KEY ASC"

rst1.Close
Set rst1 = Nothing
End Sub

The problem is with the Sort Property applied to the recordset object.

Any help greatly appreicated.

Thanks heaps

Greg
 
G

Gerald Stanley

To enable sorting, the cursor location must be adUseClient.

Even when specifying the recordset cursor location to
adUseClient, you may still have a problem as you are using
the CurrentProject connection object (as its CursorLocation
is adUseServer). If so, you will have to declare a
connection object, set it to CurrentProject.Connection,
then change its CursorLocation to adUseClient.

Hope This Helps
Gerald Stanley MCSD
 
G

Greg Horwood

Thanks Gerald. What you've suggested makes perfect sense. I'll give it a go.

Ta
 

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