Hi All
Access 2002/2007
WinXP Pro SP2
I have a strange issue with the sorting of an ADO recordset.
Background
-------------
I have a form with an unlinked subform. The subform is populated by the main form using an ADO recordset and within a begintrans/endtrans. The SQL statement used to populate it includes a Join... table aliases are used in the Join because some field names are common to both tables.
The form/subform allows management of users' print fields... it permits selection/de-selection of fields plus the movement up or down relavant to the other fields.
The leftmost table, TBL1, has
1. Unique_No - PK Autonum
2. Field_Selected - Boolean
3. List_Order - Int
4. Cntcts_Unique_No - Long - Logged-in Users' IDs
The ADO is sorted at form-open with:-
.Sort = "[Field_Selected] DESC, [TBL1.List_Order]"
All is well in the form.
Problem
---------
In case the List_Nos get out of step, I have a simple re-order routine which loops around the ADO Rs and, starting with 1 at the first record, increments the List_Nos by 1. Easy enough:-
There are a number of records which have duplicate List_Nos ... e.g. see records 799 and 697 on attached jpg.... so I call the re-order routine.
However, with the above sort applied, the msgbox for "Loop No and [TBL1.Unique_No]" reveals that duplicate[List_Nos] are missed... notice that 697 and 799 are not included in (attached) List_Loop_v01... and as a result are not re-nunbered.
If I simply change the sort to:-
.Sort = " [TBL1.Unique_No]"
then 697 and 799 are included in the loop... see (attached) List_Loop_v02...
Any ideas anyone please?
Access 2002/2007
WinXP Pro SP2
I have a strange issue with the sorting of an ADO recordset.
Background
-------------
I have a form with an unlinked subform. The subform is populated by the main form using an ADO recordset and within a begintrans/endtrans. The SQL statement used to populate it includes a Join... table aliases are used in the Join because some field names are common to both tables.
Code:
SQLLine = "SELECT TBL1.*, TBL2.* FROM ((User_Preferences AS TBL1) INNER JOIN Captions AS TBL2 ON TBL1.Captions_Unique_No=TBL2.Unique_No)
WHERE blah blah"
Set Edit_Cnn = CurrentProject.Connection
Edit_Cnn.BeginTrans
Set Edit_rstADO = New ADODB.Recordset
With Edit_rstADO
Set .ActiveConnection = Edit_Cnn
.Source = SQLLine
.LockType = adLockOptimistic
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.Open
.Sort = "[Field_Selected] DESC,[TBL1.List_Order]"
End With
The leftmost table, TBL1, has
1. Unique_No - PK Autonum
2. Field_Selected - Boolean
3. List_Order - Int
4. Cntcts_Unique_No - Long - Logged-in Users' IDs
The ADO is sorted at form-open with:-
.Sort = "[Field_Selected] DESC, [TBL1.List_Order]"
All is well in the form.
Problem
---------
In case the List_Nos get out of step, I have a simple re-order routine which loops around the ADO Rs and, starting with 1 at the first record, increments the List_Nos by 1. Easy enough:-
Code:
With Edit_rstADO
're-apply sort
.Sort = "[Field_Selected] DESC, [TBL1.List_Order]"
.MoveFirst
Do Until .EOF
MsgBox "Loop No= " & List_Order_No & ", Rec No=" & ![TBL1.Unique_No]
If ![Cntcts_Unique_No] = Curr_User_Unique_No Then
If ![TBL1.Description] = Mode_Parm Then
If ![TBL1.Deleted] = False Then
List_Order_No = List_Order_No + 1
![TBL1.List_Order] = List_Order_No
.MoveNext
Else
![TBL1.List_Order] = "-1"
.MoveNext
End If
End If
End If
Loop
End With
There are a number of records which have duplicate List_Nos ... e.g. see records 799 and 697 on attached jpg.... so I call the re-order routine.
However, with the above sort applied, the msgbox for "Loop No and [TBL1.Unique_No]" reveals that duplicate[List_Nos] are missed... notice that 697 and 799 are not included in (attached) List_Loop_v01... and as a result are not re-nunbered.
If I simply change the sort to:-
.Sort = " [TBL1.Unique_No]"
then 697 and 799 are included in the loop... see (attached) List_Loop_v02...
Any ideas anyone please?