Solved

function or interface marked as restricted or the function uses an automation type not supported in visual basic

Posted on 2014-01-22
7
1,550 Views
Last Modified: 2014-01-30
I get the follow error:
"function or interface marked as restricted or the function uses an automation type not supported in visual basic"

when running this code:
        For i = 1 To 14
        StateWide.Controls("Check" & i) = rec.Fields(("StateWideCheck" & i))
        Next i

Why doesn't Controls("Check" & i) work in vb6?
0
Comment
Question by:al4629740
7 Comments
 
LVL 12

Expert Comment

by:jkaios
ID: 39802006
What type of control is "StateWide"?  Is it a form?

One of the following scenarios may be true:

  1) StateWide doesn't have a property called "Controls"

  2) the "Controls" property of object StateWide does not support string as in "check"

  3) try StateWide.Controls(i) instead
0
 

Author Comment

by:al4629740
ID: 39802046
It is a form
0
 
LVL 5

Expert Comment

by:advfinance
ID: 39802565
Maybe try explicitly stating the properties you are wishing to call the setter/getter for rather than using the default property?

StateWide.Controls("Check" & i).Text = rec.Fields(("StateWideCheck" & i)).Value

Open in new window


--
Chris
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 12

Assisted Solution

by:jkaios
jkaios earned 250 total points
ID: 39804759
Assuming that you have specified the correct field name (in the DataField property) on each control on the form, the following code should suffice.

   Dim ctl As Control
   For Each ctl In StateWide.Controls
      If TypeName(ctl) = "TextBox" Then
         If Len(ctl.DataField) Then
            ctl.Text = rec.Fields(ctl.DataField)
         End If
      End If
   Next

Open in new window

0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 125 total points
ID: 39805473
If this is VB6, you do not have the ability to reference an individual item in the Controls collection by name.  You can only reference it by number or iteration.
Example using the control name to reference the field
   Dim ctl As Control, lngNum As Long
   For Each ctl In StateWide.Controls
      If ctl.Name Like "Check#*" Then
            lngNum = Val(Mid(ctl.Name, 6))
            ctl.Value = rec.Fields("StateWideCheck" & lngNum)
      End If
   Next

Open in new window


If performance is a concern, you can create your own collection and then iterate through that collection.
Example using a custom collection
Option Explicit
Dim colChecks As New Collection

Sub Form_Load()
   Dim ctl As Control
   For Each ctl In StateWide.Controls
      If ctl.Name Like "Check#*" Then
            colChecks.Add ctl
      End If
   Next
   
End Sub

'code in your update routine
   Dim ctl As Control, lngLoop as Long
   For lngLoop = 1 to 14
            Set ctl = colChecks(lngLoop)
            ctl.Value = rec.Fields("StateWideCheck" & lngLoop)
   Next

Open in new window

0
 
LVL 27

Assisted Solution

by:Ark
Ark earned 125 total points
ID: 39805553
If this is VB6, you do not have the ability to reference an individual item in the Controls collection by name.
Private Sub Command1_Click()
   MsgBox Me.Controls("Command1").Width
End Sub

Open in new window

:)
The error comes with lazy habbit of using default properties instead of explicit setting property you need. The default property of checkbox is Value (Enum/Integer) and doesn't accept strings or Null. To reproduce error just write Check1="aaa"
If Fields(("StateWideCheck" & i)) is a boolean (bit)  - check it for NULL first. If it's a string - convert to boolean or use string property (.caption, for example)
0
 
LVL 12

Accepted Solution

by:
jkaios earned 250 total points
ID: 39810735
If this is VB6, you do not have the ability to reference an individual item in the Controls collection by name

The "TypeName()" function to is used check the "type of" control (similar to the Type Of keyword), except that it uses late binding - NOT the name.  The sample code provided is from a live working test project.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question