Changing the Control Source

C

Carlos

Hi, I have a main form called "Financials Main Form", which contains a
subform called "Assets Subform". The main form has a textbox called "Last
Year" to be used as an input from the user. The subform is referenced to a
query called "Assets", whose SQL is changed according to the input from the
textbox "Last Year".

The ControlSource property of the contrlos contained in the subform must
match the fields of the query. That is, if one control has its ControlSource
property set to "Last Year -1", then the query must have a field called "Last
Year -1".

The problem is that the SQL of the query changes successfully, but the
ControlSource property of the controls doesn't. Let TxtBox be one of the
controls. I am using the following statement:

TxtBox.ControlSource = "Last Year " & x,

where x is the value of the text box "Last Year".

Can someone explain me how should I change the ControlSource property of the
controls while the main form is running?
 
M

Marshall Barton

Carlos said:
Hi, I have a main form called "Financials Main Form", which contains a
subform called "Assets Subform". The main form has a textbox called "Last
Year" to be used as an input from the user. The subform is referenced to a
query called "Assets", whose SQL is changed according to the input from the
textbox "Last Year".

The ControlSource property of the contrlos contained in the subform must
match the fields of the query. That is, if one control has its ControlSource
property set to "Last Year -1", then the query must have a field called "Last
Year -1".

The problem is that the SQL of the query changes successfully, but the
ControlSource property of the controls doesn't. Let TxtBox be one of the
controls. I am using the following statement:

TxtBox.ControlSource = "Last Year " & x,

where x is the value of the text box "Last Year".

Can someone explain me how should I change the ControlSource property of the
controls while the main form is running?


A control source expression must be preceeded by an = sign.
try changing your code to:

Me.TxtBox.ControlSource = "=Last Year - " & Me.[Last Year]
 
C

Carlos Mallen

Hi Marshall: unfortunately using the "=" sign didn't work. There must be
something wrong besides this. Thanks a lot anyway!
--
Carlos


Marshall Barton said:
Carlos said:
Hi, I have a main form called "Financials Main Form", which contains a
subform called "Assets Subform". The main form has a textbox called "Last
Year" to be used as an input from the user. The subform is referenced to a
query called "Assets", whose SQL is changed according to the input from the
textbox "Last Year".

The ControlSource property of the contrlos contained in the subform must
match the fields of the query. That is, if one control has its ControlSource
property set to "Last Year -1", then the query must have a field called "Last
Year -1".

The problem is that the SQL of the query changes successfully, but the
ControlSource property of the controls doesn't. Let TxtBox be one of the
controls. I am using the following statement:

TxtBox.ControlSource = "Last Year " & x,

where x is the value of the text box "Last Year".

Can someone explain me how should I change the ControlSource property of the
controls while the main form is running?


A control source expression must be preceeded by an = sign.
try changing your code to:

Me.TxtBox.ControlSource = "=Last Year - " & Me.[Last Year]
 
M

Marshall Barton

Carlos said:
Hi Marshall: unfortunately using the "=" sign didn't work. There must be
something wrong besides this. Thanks a lot anyway!


What, exactly, did you use and what did it do? If there's
an error of some kind, post the error message.
 
C

Carlos Mallen

Marshall: The problem was that there were severe inconsistencies between my
SQL and the subform. For instance, at all times the names of the textboxes in
the subform must match the names of the fields in the query. While modifying
the SQL I was changing the names of the fields in the query, but didn't
notice. That's why changing the ControlSource was useless.

Thanks a lot for your interest!
 

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