Hi
Access 2007
I've noticed an issue when looping thru' an ADODB Rs?
I build an SQLLine string based on various requirements and then open the ADODB Rs with:-
Then I attach it to my form thus:-
You will notice in the .Sort above that I have 'Field_Selected' and 'List_Order' columns (the TBL1. prefix is needed on the latter cos' the SQL String has got a table join in it). There is an autonum prinary key called 'Unique_No' in the Rs.
All well and good.
The field_selected and list_order columns allow users to select various records and to 'human-sort' them in their preferred order... great.. no problem there.
Now because users might give two records the same 'list_order' number, I do an 'automatic' re-order of the list_orders in the Rs to make sure they are shipshape.
So:-
This works happily until there are two list_orders with the same number... so.... if there are 10 records total and someone marks 3 of those 10 records with, say, list_order=4... the Do Until .EOF loop updates the first list_order=4 with it's newly auro-calulated list_order but then seems to miss the 2nd and 3rd instances of list_order=4.... the result is that some of the records do not get a newly auto-calculated 'list_order'....
Of source, the whole point of the auto-re-order is to make sure each record has it's own unique list_order but it fails under these circumstances.
Any ideas anyone please?
Thanks.
Access 2007
I've noticed an issue when looping thru' an ADODB Rs?
I build an SQLLine string based on various requirements and then open the ADODB Rs with:-
Code:
Set Edit_rstADO = New ADODB.Recordset
With Edit_rstADO
Set .ActiveConnection = Edit_Cnn
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenStatic 'for adds
.CursorLocation = adUseClient
.Open
.Sort = "[Field_Selected] DESC,[TBL1.List_Order]"
End With
Then I attach it to my form thus:-
Code:
Set Cntrlbx.Form.Recordset = Edit_rstADO
You will notice in the .Sort above that I have 'Field_Selected' and 'List_Order' columns (the TBL1. prefix is needed on the latter cos' the SQL String has got a table join in it). There is an autonum prinary key called 'Unique_No' in the Rs.
All well and good.
The field_selected and list_order columns allow users to select various records and to 'human-sort' them in their preferred order... great.. no problem there.
Now because users might give two records the same 'list_order' number, I do an 'automatic' re-order of the list_orders in the Rs to make sure they are shipshape.
So:-
Code:
'First detach from form
Set Cntrlbx.Form.Recordset = Nothing
With Edit_rstADO
.MoveLast
.MoveFirst 'make sure all records are collected
.Sort = "[Field_Selected] DESC,[TBL1.List_Order]"
.MoveFirst
Do Until .EOF
If ![Cntcts_Unique_No] = Curr_User_Unique_No Then
List_Order_No = List_Order_No + 1
![TBL1.List_Order] = List_Order_No
.Update
End If
.MoveNext
Loop
End With
're-attach to form
Set Cntrlbx.Form.Recordset = edit_rstAdo
This works happily until there are two list_orders with the same number... so.... if there are 10 records total and someone marks 3 of those 10 records with, say, list_order=4... the Do Until .EOF loop updates the first list_order=4 with it's newly auro-calulated list_order but then seems to miss the 2nd and 3rd instances of list_order=4.... the result is that some of the records do not get a newly auto-calculated 'list_order'....
Of source, the whole point of the auto-re-order is to make sure each record has it's own unique list_order but it fails under these circumstances.
Any ideas anyone please?
Thanks.
Last edited: