How do I format a number in a text string to read with only 2 deci

J

jmuirman

2 questions:

(1) How do I format a number in a text string to read with only 2 decimal
points - my sentence reads:

The Taxable Equivalent Yield is 5.0857956217604581E-02% based on a 28% tax
bracket.

(2) I have a drop-down list that I designed with the wizard that has 2
columns, and I selected column 2 to use for calculations. It looks like:

Column 1 Column2
28% .28

soooo...how do I use column 2 for calculations but use column 1 in the text
string above?

Much Thanks,

John
 
D

Dirk Goldgar

jmuirman said:
2 questions:

(1) How do I format a number in a text string to read with only 2
decimal points - my sentence reads:

The Taxable Equivalent Yield is 5.0857956217604581E-02% based on a
28% tax bracket.

(2) I have a drop-down list that I designed with the wizard that has 2
columns, and I selected column 2 to use for calculations. It looks
like:

Column 1 Column2
28% .28

soooo...how do I use column 2 for calculations but use column 1 in
the text string above?


Presumably the value "5.0857956217604581E-02" is the result of a
calculation. Suppose that that result is stored in the variable
"dblResult". Then you could format it and get it into your text string
like this:

strText = _
"The Taxable Equivalent Yield is " & _
Format(5.0857956217604581E-02, "0.00") & _
"% based on a " & _
Me!cboTaxBracket.Column(0) & _
" tax bracket."

Note that the first column of a combo box is .Column(0) in VBA, and the
second is .Column(1).
 
J

jmuirman

Thanks Dirk - I got the first part to work - formating the calculation to
percent, but I cant get the column thing to work here's what I have so far:

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket] & "tax bracket."

Really appreciate your help.

John
 
D

Dirk Goldgar

jmuirman said:
Thanks Dirk - I got the first part to work - formating the
calculation to percent, but I cant get the column thing to work
here's what I have so far:

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket] & "tax
bracket."

Is [tax bracket] the combo box on your form, with columns as you
described? Did you try

" based on a " & Me![tax bracket].Column(0) & _
" tax bracket."

?
 
J

jmuirman

couldn't make it work - got a message like...doesn't have proper
syntax...operand not right ...any suggestions?

Thanks for your help,

John

Dirk Goldgar said:
jmuirman said:
Thanks Dirk - I got the first part to work - formating the
calculation to percent, but I cant get the column thing to work
here's what I have so far:

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket] & "tax
bracket."

Is [tax bracket] the combo box on your form, with columns as you
described? Did you try

" based on a " & Me![tax bracket].Column(0) & _
" tax bracket."

?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

jmuirman said:
couldn't make it work - got a message like...doesn't have proper
syntax...operand not right ...any suggestions?

Please post the exact code you tried.
 
J

jmuirman

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket] & "tax bracket."

Here it is - i copy/pasted your code - I must be doing something wrong
 
D

Dirk Goldgar

jmuirman said:
="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket] & "tax
bracket."

Here it is - i copy/pasted your code - I must be doing something wrong

That's not an exact copy/paste of my code -- you left out the .Column(0)
part, for one thing. But now I get the impression that this is being
pasted in the ControlSource of a text box, which I had overlooked
before. If that's so, it has to be slightly different from what I
originally posted, as the "Me" keyword isn't applicable then. Try this:

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket].[Column](0) &
" tax bracket."

Please note that the above was posted all one line, as it must be in the
ControlSource property, but it will have been broken onto multiple lines
by the newsreader. Be sure to join the lines together again properly.
 
J

jmuirman

now the string returns #Name?

Appreciate your patience

Dirk Goldgar said:
jmuirman said:
="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket] & "tax
bracket."

Here it is - i copy/pasted your code - I must be doing something wrong

That's not an exact copy/paste of my code -- you left out the .Column(0)
part, for one thing. But now I get the impression that this is being
pasted in the ControlSource of a text box, which I had overlooked
before. If that's so, it has to be slightly different from what I
originally posted, as the "Me" keyword isn't applicable then. Try this:

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax bracket].[Column](0) &
" tax bracket."

Please note that the above was posted all one line, as it must be in the
ControlSource property, but it will have been broken onto multiple lines
by the newsreader. Be sure to join the lines together again properly.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
D

Dirk Goldgar

jmuirman said:
now the string returns #Name?

Appreciate your patience

Dirk Goldgar said:
Try this:

="The Taxable Equivalent Yield for this proposal is " &
Format([tey1],"Percent") & " based on a " & [tax
bracket].[Column](0) & " tax bracket."

I guess we're going to need more details.

1. What are the name and type of the control that you are giving this
controlsource expression?

2. Is "tey1" really the name of a control on the form? Please verify.

3. Is "tax bracket" really the name of a combo box on the form? Please
verify.
 
Top