• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

error in vb6

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

0
al4629740
Asked:
al4629740
2 Solutions
 
sachinpatil10dCommented:
Check if this link resolves you problem

http://support.microsoft.com/kb/303829
0
 
kbireckiCommented:
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.
0
 
aikimarkCommented:
what is MR4?

What are the Activity1, Activity2, Activity3, ... controls?
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.

 
al4629740Author Commented:
kbirecki:

I still get the same error.

Activity1, Activity2, Activity3 are all textboxs on my form

MR4 is the name of the form of course...
0
 
aikimarkCommented:
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?
0
 
al4629740Author Commented:
They are not in a control array
0
 
al4629740Author Commented:
I used the following setup code

Set rec = New ADODB.Recordset
0
 
al4629740Author Commented:
thanks,  you gave me an idea to use a control array and that solved the problem.  Thanks guys!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now