PC Review


Reply
Thread Tools Rate Thread

Conditional Decimal Places

 
 
PPCO
Guest
Posts: n/a
 
      9th Apr 2009
I wanted to see if there was a way on a report or in a query to have numbers
50 or larger have no decimal places and numbers under 50 to show 2 decimal
places. I've posted this question before and was told to do this but it never
worked:

Using an unbound control, try:
=IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))

or

format(x,iif(x>50,"0","0.00"))

 
Reply With Quote
 
 
 
 
Ken Sheridan
Guest
Posts: n/a
 
      9th Apr 2009
One possible reason for it not working would be if you've named the unbound
text box control the same as the underlying field name, which would introduce
a circular reference. If so change the control's name to txtFieldname or
similar.

Another approach would be to use a hidden bound control FieldName, and in
the Format event procedure of whatever section the control is in assign a
value to a visible unbound control with:

If Me.[FieldName] >= 50 Then
Me.[txtFieldName] = Format([FieldName],"#")
Else
Me.[txtFieldName] = Format([FieldName],"#.00")
End If

Note that you have to have the hidden bound control in the report for this
as, unlike in a form's module, you cannot reference a column in a report's
underlying table or query directly in a report's module.

Ken Sheridan
Stafford, England

"PPCO" wrote:

> I wanted to see if there was a way on a report or in a query to have numbers
> 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> places. I've posted this question before and was told to do this but it never
> worked:
>
> Using an unbound control, try:
> =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))
>
> or
>
> format(x,iif(x>50,"0","0.00"))
>


 
Reply With Quote
 
PPCO
Guest
Posts: n/a
 
      4th May 2009
So I tried that approach, and its giving me the error: "Microsoft Access
can't find the macro:..." And it lists my code which is below. Something
wrong with my
code?
IIf([GoalResults]>=50, [txtgoalresults]=Format([goalresults],"#"),
[txtgoalresults]=Format([goalresults],"#.00"))

"Ken Sheridan" wrote:

> One possible reason for it not working would be if you've named the unbound
> text box control the same as the underlying field name, which would introduce
> a circular reference. If so change the control's name to txtFieldname or
> similar.
>
> Another approach would be to use a hidden bound control FieldName, and in
> the Format event procedure of whatever section the control is in assign a
> value to a visible unbound control with:
>
> If Me.[FieldName] >= 50 Then
> Me.[txtFieldName] = Format([FieldName],"#")
> Else
> Me.[txtFieldName] = Format([FieldName],"#.00")
> End If
>
> Note that you have to have the hidden bound control in the report for this
> as, unlike in a form's module, you cannot reference a column in a report's
> underlying table or query directly in a report's module.
>
> Ken Sheridan
> Stafford, England
>
> "PPCO" wrote:
>
> > I wanted to see if there was a way on a report or in a query to have numbers
> > 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> > places. I've posted this question before and was told to do this but it never
> > worked:
> >
> > Using an unbound control, try:
> > =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))
> >
> > or
> >
> > format(x,iif(x>50,"0","0.00"))
> >

>

 
Reply With Quote
 
ken@ksheridan.orangehome.co.uk
Guest
Posts: n/a
 
      4th May 2009
Firstly it sounds like you've entered it directly in the properties
sheet, not in the event procedure. This is how its done:

Select the relevant section in report design view and open its
properties sheet if its not already open. Then select the On Format
event property in the properties sheet. Click on the 'build' button;
that's the one on the right with 3 dots. Select 'Code Builder' in the
dialogue, and click OK. The VBA window will open at the event
procedure with the first and last lines already in place. Enter the
lines of code between these two existing lines.

But as well as that you've used the IIf function not an If….End If
construct. The code would be:

If Me.[GoalResults] >= 50 Then
Me.[txtGoalResults] = Format([GoalResults],"#")
Else
Me.[txtGoalResults] = Format([GoalResults],"#.00")
End If

Ken Sheridan
Stafford, England

On May 4, 3:35 pm, PPCO <P...@discussions.microsoft.com> wrote:
> So I tried that approach, and its giving me the error: "Microsoft Access
> can't find the macro:..." And it lists my code which is below. Something
> wrong with my
> code?
> IIf([GoalResults]>=50, [txtgoalresults]=Format([goalresults],"#"),
> [txtgoalresults]=Format([goalresults],"#.00"))
>
> "Ken Sheridan" wrote:
> > One possible reason for it not working would be if you've named the unbound
> > text box control the same as the underlying field name, which would introduce
> > a circular reference. If so change the control's name to txtFieldname or
> > similar.

>
> > Another approach would be to use a hidden bound control FieldName, and in
> > the Format event procedure of whatever section the control is in assigna
> > value to a visible unbound control with:

>
> > If Me.[FieldName] >= 50 Then
> > Me.[txtFieldName] = Format([FieldName],"#")
> > Else
> > Me.[txtFieldName] = Format([FieldName],"#.00")
> > End If

>
> > Note that you have to have the hidden bound control in the report for this
> > as, unlike in a form's module, you cannot reference a column in a report's
> > underlying table or query directly in a report's module.

>
> > Ken Sheridan
> > Stafford, England

>
> > "PPCO" wrote:

>
> > > I wanted to see if there was a way on a report or in a query to have numbers
> > > 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> > > places. I've posted this question before and was told to do this but it never
> > > worked:

>
> > > Using an unbound control, try:
> > > =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))

>
> > > or

>
> > > format(x,iif(x>50,"0","0.00"))


 
Reply With Quote
 
PPCO
Guest
Posts: n/a
 
      4th May 2009
I'd had the iif statement in the on format event line but hadn't used the
code builder or a straight if statement. So I did that, and its giving me the
error: "Run-Time Error '-2147352567 (80020009)'
You can't assign a value to this object"

Thanks so much for your help!

"(E-Mail Removed)" wrote:

> Firstly it sounds like you've entered it directly in the properties
> sheet, not in the event procedure. This is how its done:
>
> Select the relevant section in report design view and open its
> properties sheet if its not already open. Then select the On Format
> event property in the properties sheet. Click on the 'build' button;
> that's the one on the right with 3 dots. Select 'Code Builder' in the
> dialogue, and click OK. The VBA window will open at the event
> procedure with the first and last lines already in place. Enter the
> lines of code between these two existing lines.
>
> But as well as that you've used the IIf function not an If….End If
> construct. The code would be:
>
> If Me.[GoalResults] >= 50 Then
> Me.[txtGoalResults] = Format([GoalResults],"#")
> Else
> Me.[txtGoalResults] = Format([GoalResults],"#.00")
> End If
>
> Ken Sheridan
> Stafford, England
>
> On May 4, 3:35 pm, PPCO <P...@discussions.microsoft.com> wrote:
> > So I tried that approach, and its giving me the error: "Microsoft Access
> > can't find the macro:..." And it lists my code which is below. Something
> > wrong with my
> > code?
> > IIf([GoalResults]>=50, [txtgoalresults]=Format([goalresults],"#"),
> > [txtgoalresults]=Format([goalresults],"#.00"))
> >
> > "Ken Sheridan" wrote:
> > > One possible reason for it not working would be if you've named the unbound
> > > text box control the same as the underlying field name, which would introduce
> > > a circular reference. If so change the control's name to txtFieldname or
> > > similar.

> >
> > > Another approach would be to use a hidden bound control FieldName, and in
> > > the Format event procedure of whatever section the control is in assign a
> > > value to a visible unbound control with:

> >
> > > If Me.[FieldName] >= 50 Then
> > > Me.[txtFieldName] = Format([FieldName],"#")
> > > Else
> > > Me.[txtFieldName] = Format([FieldName],"#.00")
> > > End If

> >
> > > Note that you have to have the hidden bound control in the report for this
> > > as, unlike in a form's module, you cannot reference a column in a report's
> > > underlying table or query directly in a report's module.

> >
> > > Ken Sheridan
> > > Stafford, England

> >
> > > "PPCO" wrote:

> >
> > > > I wanted to see if there was a way on a report or in a query to have numbers
> > > > 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> > > > places. I've posted this question before and was told to do this but it never
> > > > worked:

> >
> > > > Using an unbound control, try:
> > > > =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))

> >
> > > > or

> >
> > > > format(x,iif(x>50,"0","0.00"))

>
>

 
Reply With Quote
 
PPCO
Guest
Posts: n/a
 
      4th May 2009
I'd had the iif statement in the on format event line but hadn't used the
code builder or a straight if statement. So I did that, and its giving me the
error: "Run-Time Error '-2147352567 (80020009)'
You can't assign a value to this object"

Thanks so much for your help!

"(E-Mail Removed)" wrote:

> Firstly it sounds like you've entered it directly in the properties
> sheet, not in the event procedure. This is how its done:
>
> Select the relevant section in report design view and open its
> properties sheet if its not already open. Then select the On Format
> event property in the properties sheet. Click on the 'build' button;
> that's the one on the right with 3 dots. Select 'Code Builder' in the
> dialogue, and click OK. The VBA window will open at the event
> procedure with the first and last lines already in place. Enter the
> lines of code between these two existing lines.
>
> But as well as that you've used the IIf function not an If….End If
> construct. The code would be:
>
> If Me.[GoalResults] >= 50 Then
> Me.[txtGoalResults] = Format([GoalResults],"#")
> Else
> Me.[txtGoalResults] = Format([GoalResults],"#.00")
> End If
>
> Ken Sheridan
> Stafford, England
>
> On May 4, 3:35 pm, PPCO <P...@discussions.microsoft.com> wrote:
> > So I tried that approach, and its giving me the error: "Microsoft Access
> > can't find the macro:..." And it lists my code which is below. Something
> > wrong with my
> > code?
> > IIf([GoalResults]>=50, [txtgoalresults]=Format([goalresults],"#"),
> > [txtgoalresults]=Format([goalresults],"#.00"))
> >
> > "Ken Sheridan" wrote:
> > > One possible reason for it not working would be if you've named the unbound
> > > text box control the same as the underlying field name, which would introduce
> > > a circular reference. If so change the control's name to txtFieldname or
> > > similar.

> >
> > > Another approach would be to use a hidden bound control FieldName, and in
> > > the Format event procedure of whatever section the control is in assign a
> > > value to a visible unbound control with:

> >
> > > If Me.[FieldName] >= 50 Then
> > > Me.[txtFieldName] = Format([FieldName],"#")
> > > Else
> > > Me.[txtFieldName] = Format([FieldName],"#.00")
> > > End If

> >
> > > Note that you have to have the hidden bound control in the report for this
> > > as, unlike in a form's module, you cannot reference a column in a report's
> > > underlying table or query directly in a report's module.

> >
> > > Ken Sheridan
> > > Stafford, England

> >
> > > "PPCO" wrote:

> >
> > > > I wanted to see if there was a way on a report or in a query to have numbers
> > > > 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> > > > places. I've posted this question before and was told to do this but it never
> > > > worked:

> >
> > > > Using an unbound control, try:
> > > > =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))

> >
> > > > or

> >
> > > > format(x,iif(x>50,"0","0.00"))

>
>

 
Reply With Quote
 
ken@ksheridan.orangehome.co.uk
Guest
Posts: n/a
 
      4th May 2009
My guess would be that the txtGoalResults control is either bound to
the GoalResults field, i.e. has the field name as its ControlSource
property, or it’s a computed control with some expression as its
ControlSource property. What you should have is:

1. A control named GoalResults bound to the GoalResults field, and
with its Visible property set to False (No).

2. A control named txtGoalResults with a blank ControlSource property
and its Visible property set to True (Yes).

Ken Sheridan
Stafford, England

On May 4, 7:04 pm, PPCO <P...@discussions.microsoft.com> wrote:
> I'd had the iif statement in the on format event line but hadn't used the
> code builder or a straight if statement. So I did that, and its giving methe
> error: "Run-Time Error '-2147352567 (80020009)'
> You can't assign a value to this object"
>
> Thanks so much for your help!
>
> "k...@ksheridan.orangehome.co.uk" wrote:
> > Firstly it sounds like you've entered it directly in the properties
> > sheet, not in the event procedure. This is how its done:

>
> > Select the relevant section in report design view and open its
> > properties sheet if its not already open. Then select the On Format
> > event property in the properties sheet. Click on the 'build' button;
> > that's the one on the right with 3 dots. Select 'Code Builder' in the
> > dialogue, and click OK. The VBA window will open at the event
> > procedure with the first and last lines already in place. Enter the
> > lines of code between these two existing lines.

>
> > But as well as that you've used the IIf function not an If….End If
> > construct. The code would be:

>
> > If Me.[GoalResults] >= 50 Then
> > Me.[txtGoalResults] = Format([GoalResults],"#")
> > Else
> > Me.[txtGoalResults] = Format([GoalResults],"#.00")
> > End If

>
> > Ken Sheridan
> > Stafford, England

>
> > On May 4, 3:35 pm, PPCO <P...@discussions.microsoft.com> wrote:
> > > So I tried that approach, and its giving me the error: "Microsoft Access
> > > can't find the macro:..." And it lists my code which is below. Something
> > > wrong with my
> > > code?
> > > IIf([GoalResults]>=50, [txtgoalresults]=Format([goalresults],"#"),
> > > [txtgoalresults]=Format([goalresults],"#.00"))

>
> > > "Ken Sheridan" wrote:
> > > > One possible reason for it not working would be if you've named theunbound
> > > > text box control the same as the underlying field name, which wouldintroduce
> > > > a circular reference. If so change the control's name to txtFieldname or
> > > > similar.

>
> > > > Another approach would be to use a hidden bound control FieldName, and in
> > > > the Format event procedure of whatever section the control is in assign a
> > > > value to a visible unbound control with:

>
> > > > If Me.[FieldName] >= 50 Then
> > > > Me.[txtFieldName] = Format([FieldName],"#")
> > > > Else
> > > > Me.[txtFieldName] = Format([FieldName],"#.00")
> > > > End If

>
> > > > Note that you have to have the hidden bound control in the report for this
> > > > as, unlike in a form's module, you cannot reference a column in a report's
> > > > underlying table or query directly in a report's module.

>
> > > > Ken Sheridan
> > > > Stafford, England

>
> > > > "PPCO" wrote:

>
> > > > > I wanted to see if there was a way on a report or in a query to have numbers
> > > > > 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> > > > > places. I've posted this question before and was told to do this but it never
> > > > > worked:

>
> > > > > Using an unbound control, try:
> > > > > =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))

>
> > > > > or

>
> > > > > format(x,iif(x>50,"0","0.00"))


 
Reply With Quote
 
PPCO
Guest
Posts: n/a
 
      4th May 2009
You're good--that's what it was. Don't know how that happened, but I must
have mistakenly done that earlier. Thanks!

"(E-Mail Removed)" wrote:

> My guess would be that the txtGoalResults control is either bound to
> the GoalResults field, i.e. has the field name as its ControlSource
> property, or it’s a computed control with some expression as its
> ControlSource property. What you should have is:
>
> 1. A control named GoalResults bound to the GoalResults field, and
> with its Visible property set to False (No).
>
> 2. A control named txtGoalResults with a blank ControlSource property
> and its Visible property set to True (Yes).
>
> Ken Sheridan
> Stafford, England
>
> On May 4, 7:04 pm, PPCO <P...@discussions.microsoft.com> wrote:
> > I'd had the iif statement in the on format event line but hadn't used the
> > code builder or a straight if statement. So I did that, and its giving me the
> > error: "Run-Time Error '-2147352567 (80020009)'
> > You can't assign a value to this object"
> >
> > Thanks so much for your help!
> >
> > "k...@ksheridan.orangehome.co.uk" wrote:
> > > Firstly it sounds like you've entered it directly in the properties
> > > sheet, not in the event procedure. This is how its done:

> >
> > > Select the relevant section in report design view and open its
> > > properties sheet if its not already open. Then select the On Format
> > > event property in the properties sheet. Click on the 'build' button;
> > > that's the one on the right with 3 dots. Select 'Code Builder' in the
> > > dialogue, and click OK. The VBA window will open at the event
> > > procedure with the first and last lines already in place. Enter the
> > > lines of code between these two existing lines.

> >
> > > But as well as that you've used the IIf function not an If….End If
> > > construct. The code would be:

> >
> > > If Me.[GoalResults] >= 50 Then
> > > Me.[txtGoalResults] = Format([GoalResults],"#")
> > > Else
> > > Me.[txtGoalResults] = Format([GoalResults],"#.00")
> > > End If

> >
> > > Ken Sheridan
> > > Stafford, England

> >
> > > On May 4, 3:35 pm, PPCO <P...@discussions.microsoft.com> wrote:
> > > > So I tried that approach, and its giving me the error: "Microsoft Access
> > > > can't find the macro:..." And it lists my code which is below. Something
> > > > wrong with my
> > > > code?
> > > > IIf([GoalResults]>=50, [txtgoalresults]=Format([goalresults],"#"),
> > > > [txtgoalresults]=Format([goalresults],"#.00"))

> >
> > > > "Ken Sheridan" wrote:
> > > > > One possible reason for it not working would be if you've named the unbound
> > > > > text box control the same as the underlying field name, which would introduce
> > > > > a circular reference. If so change the control's name to txtFieldname or
> > > > > similar.

> >
> > > > > Another approach would be to use a hidden bound control FieldName, and in
> > > > > the Format event procedure of whatever section the control is in assign a
> > > > > value to a visible unbound control with:

> >
> > > > > If Me.[FieldName] >= 50 Then
> > > > > Me.[txtFieldName] = Format([FieldName],"#")
> > > > > Else
> > > > > Me.[txtFieldName] = Format([FieldName],"#.00")
> > > > > End If

> >
> > > > > Note that you have to have the hidden bound control in the report for this
> > > > > as, unlike in a form's module, you cannot reference a column in a report's
> > > > > underlying table or query directly in a report's module.

> >
> > > > > Ken Sheridan
> > > > > Stafford, England

> >
> > > > > "PPCO" wrote:

> >
> > > > > > I wanted to see if there was a way on a report or in a query to have numbers
> > > > > > 50 or larger have no decimal places and numbers under 50 to show 2 decimal
> > > > > > places. I've posted this question before and was told to do this but it never
> > > > > > worked:

> >
> > > > > > Using an unbound control, try:
> > > > > > =IIf([FieldName]>=50,Format([FieldName],"#"),Format([FieldName],"#.00"))

> >
> > > > > > or

> >
> > > > > > format(x,iif(x>50,"0","0.00"))

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text box formatted to General Number with 2 decimal places NOTallowing the decimal place. p-rat Microsoft Access Form Coding 3 14th Jan 2008 05:20 PM
Subtracting two 2-decimal place numbers gives result 13-decimal places? tsdutcher@earthlink.net Microsoft Excel Worksheet Functions 5 12th Mar 2007 10:38 PM
decimal places in acces more than 2 places when importing an excel =?Utf-8?B?cm9iZXJ0cm9iZXJ0cm9iZXJ0cm9iZXJ0?= Microsoft Outlook Discussion 2 28th Sep 2005 04:41 PM
FIXED 2 DECIMAL PLACES, MUST ENTER ALL ZEROES AFTER DECIMAL POINT. =?Utf-8?B?U1VLWUtJVFRZ?= Microsoft Excel Misc 3 6th Jul 2005 01:50 PM
Conditional Formatting - number of decimal places Andrew Microsoft Excel Programming 2 12th Nov 2003 09:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:32 AM.