Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,759 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses

719 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