PDA

View Full Version : Solved: For Loop Not Initialized



akn112
09-26-2007, 12:53 PM
Hey all, im getting the error in the title when i try to use this code. It's getting stopped at the for each statement but it used to work. Not sure why it stopped :dunno



Public Sub ToggleoptOption(optOption As OptionButton, lstListBox As ListBox, OptionArray() As Control, ByVal sqlStatement As String)

Dim ctrlControl As Variant

For Each ctrlControl In OptionArray
With ctrlControl
.Value = False
End With
Next

optOption.Value = True
End Sub

Oorang
09-26-2007, 02:40 PM
I am unable to reproduce your error. Workbook corruption? Try copy pasting all the data/code to a new workbook and saving.

akn112
09-27-2007, 04:51 AM
hmm... ok, i'll try that. That's weird o.O

akn112
09-27-2007, 11:14 AM
now it says object variable or with block variable not set @ optOption.Value = True :banghead:
This is the code that calls the ToggleoptOption

Private Sub ToggleoptOption(optOption As String)
Select Case optOption
Case "Withdraw"
Set goptOption = Me.optWithdraw
Case "Desposit"
Set goptOption = Me.optDeposit
End Select

Utilities.ToggleoptOption goptOption, lstTransfers, OptionArray, gstrListBoxRowSource
End Sub

Oorang
09-27-2007, 11:48 AM
Well in the code posted you have optOption declared as string. It wouldn't have a .Value property. You would just do optOption = True. But why are you storing a boolean value in a string?

akn112
09-27-2007, 11:57 AM
Well in the code posted you have optOption declared as string. It wouldn't have a .Value property. You would just do optOption = True. But why are you storing a boolean value in a string?

well, how its supposed to work is i orignally have two on_click subs

Private Sub optWithdraw_Click()
ToggleoptOption me.optWithdraw
End Sub
Private Sub optdeposit_Click()
ToggleoptOption me.optDeposit
End Sub
Private Sub ToggleoptOption(optOption As optionbutton)
set goptOption = optOption

Utilities.ToggleoptOption goptOption, lstTransfers, OptionArray, gstrListBoxRowSource
End Sub

But doing this resulted into an error. So instead i passed a string called "optOption" to differentiate between the two (as seen in my code) maybe my problem is that the "optOption" on my form module (the string) is conflicting with my "optOption" on my utilities module (the optionbutton)

akn112
09-27-2007, 12:08 PM
hey aaron, the problem was in the variable name. Had both of them as optoption. thanks for your help!:beerchug:

Oorang
09-27-2007, 12:15 PM
I see the problem. You are trying to program mutual exclusivity. You don't need to do that. Remove those two controls and the subs that are in their events. Go look for a control called "Option Group" follow the wizrard through, then (important) after the wizrd is run go name the optButtons back to the old names. Then your code will still work and the exclusivity behavior will be automatic.

Edit: Post overlap... Glad you ran it down :) Still... look into the option group I think you will be pleased.