Programmatically Set Text Box Control Source On Form Load

T

Tony

Hi All,

I don't know if this can be done, but I'm trying to programmatically set the
control source of a text box conditionally when a form loads. For example,
if condtion A is true the control is bound to field1, else it's bound to
field2. I've tried the below with no success:

If conditionA = True then

Me.txtTextBox.ControlSource = "=Me![field1]"

else

Me.txtTextBox.ControlSource = "=Me![field2]"

End If

Any help that can offered is appreciated. Thanks.
 
F

fredg

Hi All,

I don't know if this can be done, but I'm trying to programmatically set the
control source of a text box conditionally when a form loads. For example,
if condtion A is true the control is bound to field1, else it's bound to
field2. I've tried the below with no success:

If conditionA = True then

Me.txtTextBox.ControlSource = "=Me![field1]"

else

Me.txtTextBox.ControlSource = "=Me![field2]"

End If

Any help that can offered is appreciated. Thanks.

You can't use the Me keyword in the control source of a control.

Me.txtTextBox.ControlSource = "=[field1]"
Else
Me.txtTextBox.ControlSource = "=[field2]"

should work.
Make sure the name of the control is not Field1 or Field2).
 
S

SteveM

Try:
If conditionA = True then
Me.txtTextBox.ControlSource = "field1"
Else
Me.txtTextBox.ControlSource = "field2"
End If

Steve
 

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