Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error 458 on opening form

Status
Not open for further replies.

dabruins

Programmer
Mar 9, 2005
102
0
0
CA
I am experiencing an error 458 "Variable uses an automation type not supported in Visual Basic" when opening a form. In the Form_Activate sub I call another sub setHOSfields() that enables/disables some check boxes on the form based upon the value of a related checkbox. This is where the error occurs but i cannot figure out why? Prior to calling this the arraysetup() has been initialized to contain a list of control names to check in this sub. If I move this call to the Form_Load() sub it doesn't error out but it also doesn't work because all of the controls are set to False anyway. Any ideas as to why this would fail?

Private Sub setHOSfields()
Dim ctl As Control

For i = 0 To UBound(arrsetup)
If Me.Controls(arrsetup(i) & "reqd") Then
Me.Controls(arrsetup(i) & "have").Enabled = True
Me.Controls(arrsetup(i) & "ordered").Enabled = True
Me.Controls(arrsetup(i) & "setup").Enabled = True
Else
Me.Controls(arrsetup(i) & "have").Enabled = False
Me.Controls(arrsetup(i) & "ordered").Enabled = False
Me.Controls(arrsetup(i) & "setup").Enabled = False
End If
Next i

End Sub
 
Try doing it in the Current event instead.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
I tried that traingamer but it lead to more problems due to other circumstances. I have since found that setting the control value to an instantiated variable allows me to perform comparisons on it and does seem to fix the problem as shown below.

Dim ctl As Control
Dim blnCtlVal As Boolean
For i = 0 To UBound(arrsetup)
blnCtlVal = Me.Controls(arrsetup(i) & "reqd").Value
If blnCtlVal Then
Me.Controls(arrsetup(i) & "have").Enabled = True
Me.Controls(arrsetup(i) & "ordered").Enabled = True
Me.Controls(arrsetup(i) & "setup").Enabled = True
Else
Me.Controls(arrsetup(i) & "have").Enabled = False
Me.Controls(arrsetup(i) & "ordered").Enabled = False
Me.Controls(arrsetup(i) & "setup").Enabled = False
End If
Next i
 
How are ya dabruins . . .

This is simply an example of cruching code. Compare code you've provided with the following:
Code:
[blue]   Dim [purple][b]Ping[/b][/purple] As Boolean
   
   For i = 0 To UBound(arrsetup)
      Ping = Me(arrsetup(i) & "reqd")
      Me.Controls(arrsetup(i) & "have").Enabled = [purple][b]Ping[/b][/purple]
      Me.Controls(arrsetup(i) & "ordered").Enabled = [purple][b]Ping[/b][/purple] 
Next[/blue]
See the difference!? . . .

Calvin.gif
See Ya! . . . . . .
 
Woops! . . . hit enter ahead of time:
Code:
[blue]   Dim [purple][b]Ping[/b][/purple] As Boolean
   
   For i = 0 To UBound(arrsetup)
      [purple][b]Ping[/b][/purple] = Me(arrsetup(i) & "reqd")
      Me.Controls(arrsetup(i) & "have").Enabled = [purple][b]Ping[/b][/purple]
      Me.Controls(arrsetup(i) & "ordered").Enabled = [purple][b]Ping[/b][/purple] 
Next[/blue]

Calvin.gif
See Ya! . . . . . .
 
Hey AceMan.

Yeah I now see the difference. Looks like I was testing against the control itself and not it's value on my first attempt. This is essentially what I have done on the second go round and now works just fine.

Thanks.
 
Missed that entirely [blush]

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
and just a bit more crunching with:
Code:
[blue]   Dim [purple][b]Ping[/b][/purple] As Boolean
   
   For i = 0 To UBound(arrsetup)
      [purple][b]Ping[/b][/purple] = Me(arrsetup(i) & "reqd")
      Me(arrsetup(i) & "have").Enabled = [purple][b]Ping[/b][/purple]
      Me(arrsetup(i) & "ordered").Enabled = [purple][b]Ping[/b][/purple]
      Me(arrsetup(i) & "setup").Enabled = [purple][b]Ping[/b][/purple]
   Next[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top