Link to home
Start Free TrialLog in
Avatar of Michael Paravicini
Michael ParaviciniFlag for Chile

asked on

Indirect Outside reference of a form control?

I need to access a form control from a procedure. For example, I have the form "Client" and the control "Name" then I can fill the form control like this:

Call FillForm ("Client")

Sub FillForm (FormName As Variant)
  Forms(FormName).name = "Test string"
end Sub

This works fine. However I now need to fill in many different controls of the same form and hence would like to concatenate the control as follows:

Call FillForm ("Client","Name")

Sub FillForm (FormName,FormCtrl As Variant)
  Forms(FormName).FormCtrl = "Test string"
end Sub

Obviously this does not work. Is there a way how i can reference the control from a function (i cannot use me.controls...

Thank you MIchael
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

It depends on bit on the point of origin of your code calling. If you are allready on the form, you can simply pass the form OBJECT to your function.
Sub FillForm (Frm as Form)
   frm.ControlName="SomeValue"
end Sub

Open in new window

You could call it like so:
  FillForm Me
Avatar of Michael Paravicini

ASKER

Thank you but I'm calling it from an outside function. HOwever, I have found the solution for regular forms controls:

Forms(lFormName)("xF" & lFormNumber & "L" & ctr)  = "Test string"

This works fine. I still have not found the solution for addressing in the same way BUTTONS.. Any help would very much be appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve J
Steve J

It depends on bit on the point of origin of your code calling.
Use this syntax:
Forms("formName").Controls("controlname")

Open in new window

Yahoo mail login