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

VB6 error

I get the following error in VB6:

"Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic"


It is on this line:
.Controls("Text" & k)
esql = "select * from tblMonthlyReport1 where ID = " & Key
            rec.Open (esql), conn, adOpenDynamic, adLockOptimistic
            

            
            
            For i = 16 To 43
        
            If IsNull(rec.Fields(i)) Then
            rec.Fields(i) = ""
            End If
            
            Next i
            


        Dim k As Integer

        
        For k = 1 To 23
        MR2.Controls("Text" & k) = rec.Fields(("Text" & k))
        Next k
        
        For k = 1 To 5
        MR2.Controls("Combo" & k) = rec.Fields(("Combo" & k))
        Next k
        


        
        If Not rec.EOF Then rec.MoveNext
        rec.Close

Open in new window

0
al4629740
Asked:
al4629740
  • 8
  • 7
1 Solution
 
Martin LissOlder than dirtCommented:
Dim ctl As Control

For Each ctl In Controls
    If Left$(ctl.Name, 4) = "Text" Then
        rec.Fields = ((ctl.Name))
    End If
Next

Open in new window


and similar for the combo
0
 
Martin LissOlder than dirtCommented:
Correction.

Dim ctl As Control

For Each ctl In Controls
    If Left$(ctl.Name, 4) = "Text" Then
       ctl = rec.Fields((ctl.Name))
    End If
Next

Open in new window

0
 
al4629740Author Commented:
What if each column name is preceded by 'MR2' in the rec.Fields?  I know its wrong, but like this:

Dim ctl As Control

For Each ctl In Controls
    If Left$(ctl.Name, 4) = "Text" Then
       ctl = rec.Fields((MR2.ctl.Name))
    End If
Next
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Martin LissOlder than dirtCommented:
How about this?

ctl = "MR2" & rec.Fields(ctl.Name)

If that doesn't do it then please tell me what is in rec.Fields and what you want the value in the textbox to be.
0
 
al4629740Author Commented:
Excellent.

Does this statement also work below if I try to add data to the database

For Each ctl In Controls
                If Left$(ctl.Name, 2) = "BM" Then
                    rec.Fields((ctl.Name)) = ctl
                End If
            Next
0
 
Martin LissOlder than dirtCommented:
It probably will but without the answer to my "If that doesn't work…" question I can't  be sure.
0
 
al4629740Author Commented:
The prior one does work but this does not seem to work

For Each ctl In Controls
                If Left$(ctl.Name, 2) = "BM" Then
                    rec.Fields((ctl.Name)) = ctl
                End If
            Next
0
 
Martin LissOlder than dirtCommented:
You probably should change  

rec.Fields((ctl.Name)) = ctlto

 rec.Fields((ctl.Name)) = ctl.Name
0
 
Martin LissOlder than dirtCommented:
Oops.

You probably should change  

rec.Fields((ctl.Name)) = ctl

to

 rec.Fields((ctl.Name)) = ctl.Name
0
 
al4629740Author Commented:
This is what I tried....not working

            For Each ctl In Controls
                If Left$(ctl.Name, 7) = "MR2Text" Then
                     rec.Fields((ctl.Name)) = ctl.Name
                End If
            Next
0
 
Martin LissOlder than dirtCommented:
What is the name of the control?

What is the value of rec.Fields((ctl.Name))?
0
 
al4629740Author Commented:
It is entering the actual name of each control into the database instead of the value of each control
0
 
al4629740Author Commented:
OK.  I found the problem.  It wasn't working before because I left out this statement

rec.Update

It all works great now.  Thanks!
0
 
Martin LissOlder than dirtCommented:
Okay well that is what you'd expect when you say "rec.Fields((ctl.Name)) = ctl.Name"

Try

rec.Fields((ctl.Name)) = ctl.Text

BTW all this would be easier if you were to answer my questions.
0
 
al4629740Author Commented:
I thought I did.  Maybe I will be more concise next time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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