I am new in Access and stuck on loop issue. I have two combo which are getting values from a temp table. Temp table has only one column. This table gets updated values everytime. Temp table contains value from 1 - 10. These values are used as defining range to select toggle button from 1 - 10.
Scenario: if start combo selct 9 and then on got foucs of last combo data appears only 8 & 7 because 6 does not exist in the table and here i want to get out of loop.
Table Values: 10,9,8,7,4,3,2, 1
Start Combo Value (lets say) 9
then end combo should show from 8 till 7 and does not show remaining values from the table. basically loop should break if sequence break be reading from table.
Below code is working fine in brnging whole list from table but i want to loop out as soon as sequence break based on the table recordset.
Scenario: if start combo selct 9 and then on got foucs of last combo data appears only 8 & 7 because 6 does not exist in the table and here i want to get out of loop.
Table Values: 10,9,8,7,4,3,2, 1
Start Combo Value (lets say) 9
then end combo should show from 8 till 7 and does not show remaining values from the table. basically loop should break if sequence break be reading from table.
Below code is working fine in brnging whole list from table but i want to loop out as soon as sequence break based on the table recordset.
Code:
Private Sub CmbRouteEnd_GotFocus()
Dim lListIndex As Long
Dim iCounter, iCheck As Integer
With Me.CmbRouteEnd
' .SetFocus
For lListIndex = .ListCount - 1 To 0 Step -1
.RemoveItem (lListIndex)
Next lListIndex
' .SelText = ""
End With
On Error GoTo UserForm_Initialize_Err
Dim dbs As Database
Dim rst As Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM temp ORDER BY temp.ID Desc;", dbOpenSnapshot, adopenstatic)
iCounter = cmbRouteStart
iCheck = cmbRouteStart - 1
rst.MoveFirst
With Me.CmbRouteEnd
Do
If CInt(rst![ID]) = iCheck Then
If CInt(rst![ID]) < iCounter Then
.AddItem rst![ID]
ElseIf CInt(rst![ID]) > iCounter Then
.AddItem rst![ID]
End If
End If
iCheck = iCheck - 1
rst.MoveNext
Loop Until rst.EOF
End With
UserForm_Initialize_Exit:
On Error Resume Next
rst.Close
'cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
UserForm_Initialize_Err:
MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error!"
Resume UserForm_Initialize_Exit
End Sub
Comment