Format lost after VB code

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
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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
 

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

Similar Threads


Top