A
Andrew
Hi,
I have the following code that works......
The_Loop = 0
The_Count = Me!lb_Commitment_Status.ItemsSelected.Count
Set ctl = lb_Commitment_Status
For Each varItem In ctl.ItemsSelected
The_Loop = The_Loop + 1
If The_Loop = 1 Then lb_Commitment_Status_What = "("
lb_Commitment_Status_What = lb_Commitment_Status_What &
"(Tbl_Combined.Commitment_Status)='" & ctl.ItemData(varItem) & "'"
If The_Loop < The_Count Then lb_Commitment_Status_What =
lb_Commitment_Status_What & " OR "
Next varItem
lb_Commitment_Status_What = lb_Commitment_Status_What & ")"
I am building code for an SQL and this is the first bit. There are 10
variables ('Commitment Status' in the above example) and I'd like to simplify
it using a for...next loop.
I've tried a few times but can't quite get it to work.
Here is what I have....
For I = 1 To 10
If I = 1 Then The_Field = "Commitment_Status"
If I = 2 Then The_Field = "Company"
If I = 3 Then The_Field = "Report_Period"
If I = 4 Then The_Field = "Week"
If I = 5 Then The_Field = "OTB_FY"
If I = 6 Then The_Field = "Season1"
If I = 7 Then The_Field = "PO_Distribution_Method"
If I = 8 Then The_Field = "PO_Type"
If I = 9 Then The_Field = "PO_Status"
If I = 10 Then The_Field = "Vendor"
The_Loop = 0
The_Count = Me("lb_" & The_Field).ItemsSelected.Count
Set ctl = "lb_" & The_Field
For Each varItem In ctl.ItemsSelected
The_Loop = The_Loop + 1
If The_Loop = 1 Then lb_Commitment_Status_What = "("
lb_Commitment_Status_What = lb_Commitment_Status_What &
"(Tbl_Combined.Commitment_Status)='" & ctl.ItemData(varItem) & "'"
If The_Loop < The_Count Then lb_Commitment_Status_What =
lb_Commitment_Status_What & " OR "
Next varItem
lb_Commitment_Status_What = lb_Commitment_Status_What & ")"
Next I
I get an error (Object Required) on the line: Set ctl = "lb_" &
Commitment_Status
I have the following code that works......
The_Loop = 0
The_Count = Me!lb_Commitment_Status.ItemsSelected.Count
Set ctl = lb_Commitment_Status
For Each varItem In ctl.ItemsSelected
The_Loop = The_Loop + 1
If The_Loop = 1 Then lb_Commitment_Status_What = "("
lb_Commitment_Status_What = lb_Commitment_Status_What &
"(Tbl_Combined.Commitment_Status)='" & ctl.ItemData(varItem) & "'"
If The_Loop < The_Count Then lb_Commitment_Status_What =
lb_Commitment_Status_What & " OR "
Next varItem
lb_Commitment_Status_What = lb_Commitment_Status_What & ")"
I am building code for an SQL and this is the first bit. There are 10
variables ('Commitment Status' in the above example) and I'd like to simplify
it using a for...next loop.
I've tried a few times but can't quite get it to work.
Here is what I have....
For I = 1 To 10
If I = 1 Then The_Field = "Commitment_Status"
If I = 2 Then The_Field = "Company"
If I = 3 Then The_Field = "Report_Period"
If I = 4 Then The_Field = "Week"
If I = 5 Then The_Field = "OTB_FY"
If I = 6 Then The_Field = "Season1"
If I = 7 Then The_Field = "PO_Distribution_Method"
If I = 8 Then The_Field = "PO_Type"
If I = 9 Then The_Field = "PO_Status"
If I = 10 Then The_Field = "Vendor"
The_Loop = 0
The_Count = Me("lb_" & The_Field).ItemsSelected.Count
Set ctl = "lb_" & The_Field
For Each varItem In ctl.ItemsSelected
The_Loop = The_Loop + 1
If The_Loop = 1 Then lb_Commitment_Status_What = "("
lb_Commitment_Status_What = lb_Commitment_Status_What &
"(Tbl_Combined.Commitment_Status)='" & ctl.ItemData(varItem) & "'"
If The_Loop < The_Count Then lb_Commitment_Status_What =
lb_Commitment_Status_What & " OR "
Next varItem
lb_Commitment_Status_What = lb_Commitment_Status_What & ")"
Next I
I get an error (Object Required) on the line: Set ctl = "lb_" &
Commitment_Status