Export to excel and use format to convert 0 to -

  • Thread starter mls via AccessMonster.com
  • Start date
M

mls via AccessMonster.com

I am exporting my Access data to specific cells in Excel. Most of my data has
decimal values. If at all my data has zero values then I want to replcae that
with Hypen in my Excel template. Is this possible?
 
K

Ken Snell

There are various ways one might do this. Does "all zeroes" mean something
like "0.000" as the output?

A query like this is one way to do it if the above is true:

SELECT Field1, Field2,
IIf(Replace(Field3, "0", "") = ".", "'-", Field3) AS NewField3
FROM TableName;
 
M

mls via AccessMonster.com

I will have just one '0'. Not like 0.000.
All my fields values should be replaced with - instead of 0.
And my query has to be generic as I am not sure what columns are going to be
in my export query each time.
 
K

Ken Snell

You can use the Format function to replace zero with a hyphen:

SELECT Format(FieldName, "0.000;-0.000;-")
FROM TableName;


As for your comment about "generic" because you don't know which columns are
going to be in the export query, does that mean that you'd be building the
SQL statement via VBA code?
 

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

Top