BUX <pi***@pippo.it> wrote in
news:25********************************@4ax.com:
I often have to search in a form (Form1) a value for another form
(Form2).
So I have done a table where i placed fields like this:
Field1
Forms!Form1!Control1
Field2
Forms!Form2!Control2.
I have to do a function that set Forms!Form1!Control1 with the
value in Forms!Form2!Control2 .
I want to use a variable like this
Public MyControl as Control
to pass the value from
Forms!Form1!Control1
to
Forms!Form2!Control2.
So I need a function like
Set MyControl = fGetControl(strMyControl).
Why not give the controls the same name on both forms?
Then you could do:
Forms!Form2(Forms!Form1!Control1.Name) = Forms!Form1!Control1
I'm assuming you want this to be done with a variable, so you can,
for instance, walk through a collection of controls and do the
assignment:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Forms!Form2(ctl.name) = ctl
End If
Next ctl
Set ctl = Nothing
Now, if you really wanted to abstract this, you could do something
like:
Public Sub SetFormValues(frmSource as Form, frmDestination As frm)
Dim ctl As Control
For Each ctl In frmSource.Controls
If ctl.ControlType = acTextBox Then
frmDestination(ctl.name) = ctl
End If
Next ctl
Set ctl = Nothing
End Sub
Does that help?
--
David W. Fenton
http://www.bway.net/~dfenton
dfenton at bway dot net
http://www.bway.net/~dfassoc