Assign the Control Source for a Label and a Text Box Dynamically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to develop a form which contains 12 labels and text boxes for
MonthYear combinations which I would like to derive based on a starting
month/year entered by the user. The form contains labels(lblMonth1 -12) and
text boxes (txtMonth1-12)

I have a loop to increment a counter(b) and the InMonth and InYear values
that I would like to assign as variables i.e.

Forms!frmInput!lblMonth&b.ControlSource = InMonth & " " & InYear
Forms!frmInput!txtMonth&b.ControlSource = InMonth & " " & InYear

I've played around and can not come up with the proper syntax. Any help you
can offer will be greatly appreciated.
Thanks,
Ron
 
Ron said:
I am trying to develop a form which contains 12 labels and text boxes
for MonthYear combinations which I would like to derive based on a
starting month/year entered by the user. The form contains
labels(lblMonth1 -12) and text boxes (txtMonth1-12)

I have a loop to increment a counter(b) and the InMonth and InYear
values that I would like to assign as variables i.e.

Forms!frmInput!lblMonth&b.ControlSource = InMonth & " " & InYear
Forms!frmInput!txtMonth&b.ControlSource = InMonth & " " & InYear

I've played around and can not come up with the proper syntax. Any
help you can offer will be greatly appreciated.

First, labels don't have a ControlSource property. I think what you
want is the Caption property.

If I understand what you're doing, this may be what you're after:

With Forms!frmInput
.Controls("lblMonth" & b).Caption = InMonth & " " & InYear
.Controls("txtMonth" & b).ControlSource = InMonth & " " & InYear
End With
 
Dirk,
Thank You..Ron

Dirk Goldgar said:
First, labels don't have a ControlSource property. I think what you
want is the Caption property.

If I understand what you're doing, this may be what you're after:

With Forms!frmInput
.Controls("lblMonth" & b).Caption = InMonth & " " & InYear
.Controls("txtMonth" & b).ControlSource = InMonth & " " & InYear
End With


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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

Back
Top