Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

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

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of al4629740

ASKER

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
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.
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
It probably will but without the answer to my "If that doesn't work…" question I can't  be sure.
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
You probably should change  

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

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

You probably should change  

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

to

 rec.Fields((ctl.Name)) = ctl.Name
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
What is the name of the control?

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

rec.Update

It all works great now.  Thanks!
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.
I thought I did.  Maybe I will be more concise next time.