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,476 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
Comment Utility
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
Comment Utility
It is a form
0
 
LVL 5

Expert Comment

by:advfinance
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Assisted Solution

by:jkaios
jkaios earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now