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,514 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

895 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

12 Experts available now in Live!

Get 1:1 Help Now