al4629740
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)
"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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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.
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.
ASKER
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
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.
ASKER
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
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
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
You probably should change
rec.Fields((ctl.Name)) = ctl
to
rec.Fields((ctl.Name)) = ctl.Name
ASKER
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
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))?
What is the value of rec.Fields((ctl.Name))?
ASKER
It is entering the actual name of each control into the database instead of the value of each control
ASKER
OK. I found the problem. It wasn't working before because I left out this statement
rec.Update
It all works great now. Thanks!
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.
Try
rec.Fields((ctl.Name)) = ctl.Text
BTW all this would be easier if you were to answer my questions.
ASKER
I thought I did. Maybe I will be more concise next time.
Open in new window
and similar for the combo