How to use index in VBA code

SKV

Active Member
Joined
Jan 7, 2009
Messages
257
I have a table with 3 indexes (index1, index2, index3). I want to use each index for specific logic. So for each logic I try to set the index with following code, it fails at rs1.index = "index name". I get an error 3251. Please advise as how can use a specific index for my code.

'Option Compare Database
'
'Dim Db As DAO.Database
'
'Dim rs1 As DAO.Recordset ' for requirement table
'
'Dim cnt As Integer
'cnt = 1
'
'Dim dd As String
'Set Db = CurrentDb()
'
'Set rs1 = Db.OpenRecordset("T_InvReq_A_010_InvMoves", dbOpenDynaset) ' Inv moves transactions
''rs1.Index = "Index3"
'With rs1
' .MoveLast
' .MoveFirst
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
What do you want to do with the index in the code?
 
Upvote 0
I want to use this index to rank the records. Example I want to use index1 to rank based on wt and use index2 to rank based on (city and state) etc.
 
Upvote 0
Hi,
I think you must use a table type recordset to set an index. Indexes per se don't provide any ranking so it's not entirely clear why you want to set an index here.
 
Upvote 0

Forum statistics

Threads
1,215,793
Messages
6,126,936
Members
449,349
Latest member
Omer Lutfu Neziroglu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top