Format lost after VB code

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

Guest

Access2003

I'm summing several bound fields to an unbound field that has it's format
property to "Percent". However, after running the code, the format is lost
and the number shows up as just a number - no percentage formatting. What
gives?

Here's how I have my code:

Dim stTotal as String
Dim stRound as String

stTotal = Nz([FieldOne],0) + Nz([FieldTwo],0) + etc
stRound = Round (stTotal,4)

Me.Total.Value = stRound

I tried adding:
Me.Total.Format = Percent
but that just seems to change it to a text format (it left justifies).

Any ideas?

TIA

Aaron G
Philadelphia, PA
 
Aaron:

This may sound strange, but I have had problems with the Nz function, in the
past. What if you try this?

stTotal = iif(isnull([FieldOne]),0,[FieldOne]) +
iif(isnull([FieldTwo]),0,[FieldTwo]) + etc

As I recall, the trouble I came across was that Access was converting data
types, when using Nz. (It's been a couple of years since I've seen it...)

Good luck.

Sharkbyte
 
Sharkbyte,

That didn't work either. It just gave the same result. Thanks anyway.

Aaron G
Philadelphia, PA

Sharkbyte said:
Aaron:

This may sound strange, but I have had problems with the Nz function, in the
past. What if you try this?

stTotal = iif(isnull([FieldOne]),0,[FieldOne]) +
iif(isnull([FieldTwo]),0,[FieldTwo]) + etc

As I recall, the trouble I came across was that Access was converting data
types, when using Nz. (It's been a couple of years since I've seen it...)

Good luck.

Sharkbyte





Aaron G said:
Access2003

I'm summing several bound fields to an unbound field that has it's format
property to "Percent". However, after running the code, the format is lost
and the number shows up as just a number - no percentage formatting. What
gives?

Here's how I have my code:

Dim stTotal as String
Dim stRound as String

stTotal = Nz([FieldOne],0) + Nz([FieldTwo],0) + etc
stRound = Round (stTotal,4)

Me.Total.Value = stRound

I tried adding:
Me.Total.Format = Percent
but that just seems to change it to a text format (it left justifies).

Any ideas?

TIA

Aaron G
Philadelphia, PA
 
I figured it out myself... silly mistake. I had set the VB code as String as
opposed to Single. Works fine now!

Aaron G
Philadelphia, PA
 
Back
Top