conditional punctuation in a report

  • Thread starter Thread starter David Newmarch
  • Start date Start date
D

David Newmarch

In a report I want the value of a textbox to appear within parentheses when a
Yes/No field in the underlying query is positive and without parentheses if
the Yes/No field negative. For example, if the value of checkbox chkActive is
True, and the value of textbox txtOrderID is, say, CW259, then I want that
value to appear in the textbox without any punctuation as "CW259". If
chkActive is False then I want the value to appear in parenthesies as
"(CW259)".

I assume that it might be done with some sort of "On Load" code, but I have
no idea how to code the presence or absence of the desired punctuation. Can
anyone suggest a way to do this? Very grateful for any light you can shed.
 
I will assume that you are sorting by the value of orderId.

Assumption: field names are Active and OrderID

You can set the control's source to:
=IIF([Active]=True,"(" & [OrderID] & ")",[OrderID])

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
Thanks very much John, problem solved. I had already, unsuccessfully, tried
this solution, except that I forgot the need for the square brackets! I
seldom have to write expressions, and I'm obviously very rusty. Your help is
much appreciated.

David

John Spencer said:
I will assume that you are sorting by the value of orderId.

Assumption: field names are Active and OrderID

You can set the control's source to:
=IIF([Active]=True,"(" & [OrderID] & ")",[OrderID])

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

David said:
In a report I want the value of a textbox to appear within parentheses when a
Yes/No field in the underlying query is positive and without parentheses if
the Yes/No field negative. For example, if the value of checkbox chkActive is
True, and the value of textbox txtOrderID is, say, CW259, then I want that
value to appear in the textbox without any punctuation as "CW259". If
chkActive is False then I want the value to appear in parenthesies as
"(CW259)".

I assume that it might be done with some sort of "On Load" code, but I have
no idea how to code the presence or absence of the desired punctuation. Can
anyone suggest a way to do this? Very grateful for any light you can shed.
 
Sorry Steve, even I can see that this is a useless answer. I made it pretty
clear that "CW259" is just ONE possible value for the control.

Steve said:
Hello David,

Open your report in design view and select txtOrderID. Open properties and
go to the Data tab. Put the following expression in the Control Source
property:

=IIF([chkActive],"CW259","(CW259)")

Steve
(e-mail address removed)



David Newmarch said:
In a report I want the value of a textbox to appear within parentheses
when a
Yes/No field in the underlying query is positive and without parentheses
if
the Yes/No field negative. For example, if the value of checkbox chkActive
is
True, and the value of textbox txtOrderID is, say, CW259, then I want
that
value to appear in the textbox without any punctuation as "CW259". If
chkActive is False then I want the value to appear in parenthesies as
"(CW259)".

I assume that it might be done with some sort of "On Load" code, but I
have
no idea how to code the presence or absence of the desired punctuation.
Can
anyone suggest a way to do this? Very grateful for any light you can shed.
 
Back
Top