dynamically set text box control source?

supmktg

Registered User.
Local time
Today, 10:33
Joined
Mar 25, 2002
Messages
360
I need to view the data in an imported excel table. I have set up a continuous form with textboxes named txt1, txt2, ... through txt16. After import, I run a function to write the field number and field name to a table. I can dynamically set the control source of the textboxes on my form using dlookup:

Me.txt1.ControlSource = DLookup("fieldname", "tblxlfields", "FieldNo = " & 1)
Me.txt2.ControlSource = DLookup("fieldname", "tblxlfields", "FieldNo = " & 2)
Me.txt3.ControlSource = DLookup("fieldname", "tblxlfields", "FieldNo = " & 3)
etc.

I'd like to improve the code by looping through the textboxes and field names.

Can someone help me?

Thanks,
Sup
 
Try
Code:
For X = 1 to 16
  Me("txt" & X).ControlSource = DLookup("fieldname", "tblxlfields", "FieldNo = " & X)
Next X
 
Thank you that works perfectly!

sup
 

Users who are viewing this thread

Back
Top Bottom