Format Function

S

scott

Below is a snipplet of code that gets a recordset. I'm trying to output to a
text file and keep my columns of data straight by using tabs. Because of the
length of records in the field objRS!sShift, the vbTab code wasn't lining my
column correctly, so I used the Format() function with the "@@@@@@"
parameter and my data from the objRS!sShift now right-aligns.

My new problem is I have a new field called "percentData" that is a percent
that I need to display as 54.62% for example. Without the Format() function,
the raw output of this field looks like 0.5462625 for example.

I can't seem to find a website that shows the different parameters for the
Format() function that could help me format my percent properly.

Anyone know what parameters to use with Format() to format a percent? Any
web links would be appreciated.


CODE:

sTableRecord = objRS!ID & Chr(9) & Chr(9) & "" & _
objRS!field1 & "" & vbTab & "" & _
Format(objRS!dtDateField, "mm/dd/yyyy") & "" &
vbTab & vbTab & _
Format(objRS!sShift, "@@@@@@") & vbCrLf
 
J

J_Goddard via AccessMonster.com

Hi -

Try the FormatPercent function. (No, I didn't know about it either, until I
looked at the help!)

FormatPercent(.5462525,2) yields "54.63%"

John
 
D

Douglas J. Steele

What version of Access are you using? While you're in the VB Editor, you
should be able to highlight the word Format and hit F1, and you'll get help
on the Format function.

To format a percent, you can use either Format(percentData, "Percent") or
Format(percentData, "0.00%") (or however many decimal points you want.)

Another way to get a 6 character field to right-align would be:

Right(Space(6) & objRS!sShift, 6)
 
S

scott

Access 2003. What does the version of Access have to do with the
FormatPercent function?
 
D

Douglas J. Steele

Text is always left-formatted (and the format function converts whatever's
being formatted to a string), so I don't really understand what you're
looking for.
 

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