[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • 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 LissRetired ProgrammerCommented:
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 LissRetired ProgrammerCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Martin LissRetired ProgrammerCommented:
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 LissRetired ProgrammerCommented:
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 LissRetired ProgrammerCommented:
You probably should change  

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

 rec.Fields((ctl.Name)) = ctl.Name
0
 
Martin LissRetired ProgrammerCommented:
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 LissRetired ProgrammerCommented:
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 LissRetired ProgrammerCommented:
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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