How can i loop through a combo box?

  • Thread starter Thread starter nesster13
  • Start date Start date
N

nesster13

Thanks in advance.

Does anybody know how I can loop through a combo box on a form.
For Example, I have a combo box on a form name "Test" with value
(1,2,3,4). Now I need a VB code that can help me loop through this
combo box and return each value in the combo box:1,2,3,4.

Any help is greatly appreciated. Thanks
 
Here is the code that I have:

Private Sub PreviewAll_Click()
On Error GoTo Err_PreviewAll_Click

Dim stDocName As String

For i = 0 To [Forms]![ReportChooser]![MonthTest].ListCount - 1

Forms!ReportChooser!Month =
[Forms]![ReportChooser]![MonthTest].List(i)

stDocName = "CFDMonthlyReport Design 2"
DoCmd.OpenReport stDocName, acNormal

Next

Exit_PreviewAll_Click:
Exit Sub

Err_PreviewAll_Click:
MsgBox Err.Description
Resume Exit_PreviewAll_Click

End Sub

Once I click the PreviewAll_Click button the error that I have is:
Object doesn't support this property or method


Does anybody know what is wrong with my code? Thanks
 
I have figure out a way to do this now. Just in case somebody come
accross something similar, I have attached my code below.

Private Sub PrintAll_Click()
On Error GoTo Err_PrintAll_Click

Dim stDocName As String
Dim i As Integer
i = 0

'Loop through all the data within the combo box and assign value
then print the report
Do While ComboBoxName.ItemData(i) <> ""
ComboBoxName = ComboBoxName.ItemData(i)
stDocName = "ReportName"
DoCmd.OpenReport stDocName, acNormal
i = i + 1
Loop

Exit_PrintAll_Click:
Exit Sub

Err_PrintAll_Click:
MsgBox Err.Description
Resume Exit_PrintAll_Click

End Sub

I hope somebody will find this useful. Thanks for all the help with
previous posts.
Khoa
 
Khoa,

Thanks for posting -- after trying other suggestions, and beating my head
against the wall, your solution worked and was the easiest to implement.

Thanks a bunch!

Allan
 
Back
Top