for each ctl

J

Jason

Hi,

I have created this code which populates values in a report from a form
without using a recordsource in the report.

The problem is that each control in the report gets the same value of a
control in the form. I know i'm forgetting something, but can't figure out
what.

Here's my code:
'ctl1 are the controls in a form and ctl2 are the controls in a report. Both
controls have 'the same names.

dim ctl1 as control
dim ctl2 as control

For Each ctl1 In Form_MyForm.Controls
If ctl1.ControlType = acTextBox Then
For Each ctl2 In Me.Controls
If ctl2.ControlType = acTextBox Then
ctl2.ControlSource = "='" & ctl1 & "'"
End If
Next
End If
Next
 
A

Alex Dybenko

hi,
not sure i understand what you want to acheive, but with this code:

For Each ctl2 In Me.Controls
If ctl2.ControlType = acTextBox Then
ctl2.ControlSource = "='" & ctl1 & "'"
End If
Next

you bind all textboxes to same value
i think you have to revise your code
 
J

Jason

Hi Alex,

How should it be. Alle controls should have different values based on the
controls on the form, but i'm getting only one value on all controls.
 
D

Dirk Goldgar

Jason said:
Hi,

I have created this code which populates values in a report from a
form without using a recordsource in the report.

The problem is that each control in the report gets the same value of
a control in the form. I know i'm forgetting something, but can't
figure out what.

Here's my code:
'ctl1 are the controls in a form and ctl2 are the controls in a
report. Both controls have 'the same names.

dim ctl1 as control
dim ctl2 as control

For Each ctl1 In Form_MyForm.Controls
If ctl1.ControlType = acTextBox Then
For Each ctl2 In Me.Controls
If ctl2.ControlType = acTextBox Then
ctl2.ControlSource = "='" & ctl1 & "'"
End If
Next
End If
Next

I think maybe this is what you're looking for:

For Each ctl1 In Forms!MyForm.Controls
With ctl1
If .ControlType = acTextBox Then
Me.Controls(.Name).ControlSource = "='" & .Value & "'"
End If
End With
Next
 
J

Jason

No, because i get my recordsource from sql server through an ado-recordset.
Access 2000 doesn't support recordset in a report.

But Dirk's correction did the job.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top