Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
1,829 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Assisted Solution

by:jkaios
jkaios earned 1000 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 46

Assisted Solution

by:aikimark
aikimark earned 500 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 28

Assisted Solution

by:Ark
Ark earned 500 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 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

916 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