Bound Control - make respective label use field desc

S

SAC

I have a form with bound controls with respective labels.

Each text box is name "txt"+Data Source Name (field name)

Each respective label in captioned as "lbl"+Data Source Name

I would like to loop through the form, grab the text box's data source
property and set it's corresponding label's caption property to the data
source property.

Any ideas?

Thanks.
 
M

MacDermott

You could try this:
(WARNING: AIR CODE)

Dim ctl as control
Dim lbl as control
DoCmd.OpenForm "MyForm",acDesignView
For each ctl in Forms!MyForm.Controls
if typeof ctl is textbox then
if ctl.ControlSource<>"" then
ctl.controls(0).caption=ctl.ControlSource
endif
endif
next

DoCmd.Close acForm, "MyForm", acSaveYes

You may need some error trapping if you have any bound textboxes with no
associated labels.
 

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