Convert string to a control name on another form

I

Ivan Grozney

I found Allen Browne's tip on converting a string to a control name.

Dim strControlName As String
strControlName = "City"
Me(strControlName) = "New York"

I need to do the same thing but the control is on a different form. I have
one form to search our City db for all the streets. Then from the lookup
form, I need to paste the information back to the calling form (or sub form).
There are some 27 places where I need to do this so trying to use one form
would be nice. Here is what I am trying to do...

' Detect which cmd called this form
If Forms!frmcallmain!txtWhoDunIt = "Main" Then
strSendToAdd = "frmCallMain!txtCallAddress"
strSendToLocID = "FrmCallMain!txtCustLocid"
ElseIf Forms!frmcallmain!txtWhoDunIt = "SW" Then
strSendToAdd = "Forms!frmcallmain!frmSolidWaste2!txtServiceAddress"
strSendToLocID = "Forms!frmcallmain!frmSolidWaste2!txtServiceLocID"
ElseIf ...
End If

'Send the requested address back to the requesting txtbx on the proper form
Dim i As Integer
For i = 0 To AltAddressList.ListCount - 1
If AltAddressList.Selected(i) Then
(Forms!(SendToLocID)) = Me.AltAddressList.Column(0, i)
(Forms!(strSendToAdd)) = Me.AltAddressList.Column(1, i)
End If
Next i
....

I am guessing it is something fairly simple but I cannot get it working.

tia

Vanya
 
K

Klatuu

I could not tell from your code, where you want to do this, but if you want
to identify a control by a string name in another open form:

Forms!NameOfForm.Controls(strControlName)
 
I

Ivan Grozney

Thanks. Good information to have.

Klatuu said:
I could not tell from your code, where you want to do this, but if you want
to identify a control by a string name in another open form:

Forms!NameOfForm.Controls(strControlName)
 
Top