Set Textbox Control Source Programatically.

  • Thread starter Thread starter Alan Z. Scharf
  • Start date Start date
A

Alan Z. Scharf

1. Is there a way to set a detail text box control source
programmatically?

2. I have a table of Contacts with several fields for different phone
numbers, e.g. office phone, office fax, home phone, home fax, cell phone,
etc.

3. I have a detail report listing the contacts.

For asingle visible PhoneUsed field in the detail line, I want to use the
value from one of the invisible different phone fields above, which are
also
on the detail line.

4. Can I change the control source of the one visible PhoneUsed to the
field
name of one of the invisible fields, depending a the value of the grouping
field, or can the control source be set only in design mode?

Thanks..

Alan
 
Alan said:
1. Is there a way to set a detail text box control source
programmatically?

2. I have a table of Contacts with several fields for different phone
numbers, e.g. office phone, office fax, home phone, home fax, cell phone,
etc.

3. I have a detail report listing the contacts.

For asingle visible PhoneUsed field in the detail line, I want to use the
value from one of the invisible different phone fields above, which are
also
on the detail line.

4. Can I change the control source of the one visible PhoneUsed to the
field
name of one of the invisible fields, depending a the value of the grouping
field, or can the control source be set only in design mode?


On a form, you can change a control's ControlSource property
most any time:
Me.controlname.ControlSource = "fieldname"

In a report, a control's ControlSource property can only be
changed in the report's Open event, so your idea is not
viable in a report.

Besides, this is not really the best way to accomplish your
goal. For reports, you can just set the control's Value
property to the desired field's value. The VBA code in the
section's Format event might look a little like:

If Not IsNull(Me.[office phone]) Then
Me.PhoneUsed = Me.[office phone]
ElseIf Not IsNull(Me.[cell phone]) Then
Me.PhoneUsed = Me.[cell phone]
. . .
End If
 
Thanks very much for the help.

That should work for me.

Alan

Marshall Barton said:
Alan said:
1. Is there a way to set a detail text box control source
programmatically?

2. I have a table of Contacts with several fields for different phone
numbers, e.g. office phone, office fax, home phone, home fax, cell phone,
etc.

3. I have a detail report listing the contacts.

For asingle visible PhoneUsed field in the detail line, I want to use the
value from one of the invisible different phone fields above, which are
also
on the detail line.

4. Can I change the control source of the one visible PhoneUsed to the
field
name of one of the invisible fields, depending a the value of the grouping
field, or can the control source be set only in design mode?


On a form, you can change a control's ControlSource property
most any time:
Me.controlname.ControlSource = "fieldname"

In a report, a control's ControlSource property can only be
changed in the report's Open event, so your idea is not
viable in a report.

Besides, this is not really the best way to accomplish your
goal. For reports, you can just set the control's Value
property to the desired field's value. The VBA code in the
section's Format event might look a little like:

If Not IsNull(Me.[office phone]) Then
Me.PhoneUsed = Me.[office phone]
ElseIf Not IsNull(Me.[cell phone]) Then
Me.PhoneUsed = Me.[cell phone]
. . .
End If
 
Back
Top