Modifying control source

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

Guest

Hi!

In my report, I want to change the control source of an unbound textbox
(Textbox3) depending of the value of 2 other text boxes (Textbox1 and
Textbox2). These last 2 are number fields from a query

If Me!Textbox1 >=Me!Textbox2
Me! Textbox3.controlsource = [Control1]
Else
Me!Textbox3.controlsource = [control2]
end if

i want to put whis code so that the controlsource will change depending of
the value but I don't know where to put it in my code. If I put it in
onFormat or onprint (in detail section), i get an error that says that
controlsource can't be changed after printing has started, if I put this in
onOpen event (in report), I get an error 2426, you entered an expression
that has no value

How can I make this work?
I'm using access 2000. I don't know if it changes anything but this report
is used as a subreport in another report

Thanks a lot

LouisPat
 
You are attempting to do this too late. I'm not sure what your requirements
are but you could use two text boxes. Bind them to different control sources
and use your code to make one visible and the other invisible.
 
Thanks!
This works well

Louis Pat

Duane Hookom said:
You are attempting to do this too late. I'm not sure what your requirements
are but you could use two text boxes. Bind them to different control sources
and use your code to make one visible and the other invisible.

--
Duane Hookom
MS Access MVP
--

LouisPat said:
Hi!

In my report, I want to change the control source of an unbound textbox
(Textbox3) depending of the value of 2 other text boxes (Textbox1 and
Textbox2). These last 2 are number fields from a query

If Me!Textbox1 >=Me!Textbox2
Me! Textbox3.controlsource = [Control1]
Else
Me!Textbox3.controlsource = [control2]
end if

i want to put whis code so that the controlsource will change depending of
the value but I don't know where to put it in my code. If I put it in
onFormat or onprint (in detail section), i get an error that says that
controlsource can't be changed after printing has started, if I put this
in
onOpen event (in report), I get an error 2426, you entered an expression
that has no value

How can I make this work?
I'm using access 2000. I don't know if it changes anything but this report
is used as a subreport in another report

Thanks a lot

LouisPat
 
This can be done, I just wrote the code to do it, provided these
things...

Textbox1 and TextBox2 are bound to fields from a table ( I am assuming
the form is bound to a table)

The controlsource that you want to bind TextBox3 and Textbox4 to are in
fact fields in that same table

If those things are in place the following code should work...

Private Sub Form_Current()
If TextBox1.Value > Textbox2.Value Then
TextBox3.ControlSource = "text1"
Else
TextBox3.ControlSource = "text2"
End If
End Sub

Notice that the event is the Form current event and that the control
sources are the string representation of the field names back in the
table.
 
This can be done, I just wrote the code to do it, provided these
things...

Textbox1 and TextBox2 are bound to fields from a table ( I am assuming
the form is bound to a table)

The controlsource that you want to bind TextBox3 and Textbox4 to are
in fact fields in that same table

If those things are in place the following code should work...

Private Sub Form_Current()
If TextBox1.Value > Textbox2.Value Then
TextBox3.ControlSource = "text1"
Else
TextBox3.ControlSource = "text2"
End If
End Sub

Notice that the event is the Form current event and that the control
sources are the string representation of the field names back in the
table.

Except that the OP wants to do this in a Report where it cannot be done
after the Open event has occurred.
 
Back
Top