error in vb6

Posted on 2011-10-20
Last Modified: 2012-05-12
I receive the following error when I run my code:
Compile error: Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.

The error points to line8:   .Controls("Activity" & i) =

How can I rewrite this part of the loop sequence so that it works.

I am using VB6

Do While Not rec.EOF
            i = i + 1
                If Not rec.Fields("Activity") = "" Then
                    MR4.Controls("Activity" & i) = rec.Fields("Activity")
                End If

Open in new window

Question by:al4629740
    LVL 9

    Expert Comment

    Check if this link resolves you problem
    LVL 11

    Accepted Solution

    al4629740, What is your connectivity to the recordset "rec"?  Is it DAO, ADO, or what?  Can you show the setup code for "rec".  sachinpatil10d could have identified the problem if it is DAO.

    Also, I've run into circumstances where I had to separate a statement like the following because it didn't worked combined, or it helped in troubleshooting.  Can you try this inside your If/End If statement?

    Dim strValue as string    'I'm assuming the field is string - adjust as necessary
    strValue = rec.Fields("Activity")
    MR4.Controls("Activity" & i) = strValue

    Open in new window

    The benefit to this concept, if only for testing, is that you can determine if the problem is with the left side or right side of the original statement and you would be narrowing down where the problem is.  

    Q1) I'm assuming MR4 is the form reference, so that part looks fine, assuming you have controls named exactly "Activity1", Activity2", etc. (assuming that is your range for "i".)  If, however, this is supposed to reference an array of controls, then this could be incorrect.  Can you confirm if your controls are explicitly named "Activity1", Activity2", etc. or if they are an array of controls.

    Q2) The assignment of rec.Fields("Activity") to strValue (or whatever you use) could be a problem if the recordset does not have a field named "Activity".  Can you add a line before the assignment such as
    debug.print "[" & rec.Fields("Activity") & "]"

    Open in new window

    ...and see if you get a result in the debug window that you expect.
    LVL 44

    Expert Comment

    what is MR4?

    What are the Activity1, Activity2, Activity3, ... controls?

    Author Comment


    I still get the same error.

    Activity1, Activity2, Activity3 are all textboxs on my form

    MR4 is the name of the form of course...
    LVL 44

    Assisted Solution

    Are the textboxes items in a control array?  If so, they must be addressed differently.
    MR4.Activity(i) = rec.Fields("Activity")

    Open in new window

    Note: By default, the first item in a control array is (0)

    Is it possible that you have more than three records in your recordset?

    Author Comment

    They are not in a control array

    Author Comment

    I used the following setup code

    Set rec = New ADODB.Recordset

    Author Closing Comment

    thanks,  you gave me an idea to use a control array and that solved the problem.  Thanks guys!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    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…

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now