I generally agree that you probably should have two/three
fields in the table. As long as <=1 can be used to
determine if the value is a percent or an amount, it is not
really necessary to change the table.
If you do not want or can't change the table, use two text
boxes. However, you do not need that kind of code. In
fact, you can not use that kind of code if the form is
displayed in continuous or datasheet view.
Place the formatting text box with the expression:
=IIf(DedSingPDIn <= 1, Format(DedSingPDIn, "0.00%"),
Format(DedSingPDIn, "$#,###.00"))
exactly on top of the DedSingPDIn text box.
Use this line of code in the formatting text box's GotFocus
event:
Me.DedSingPDIn.SetFocus
When the DedSingPDIn text box receives the focus, it will
automatically jump in front of the formatting text box so
the number can be edited normally. When the focus moves
away, the formatting text box will move back to the front.
--
Marsh
MVP [MS Access]
I think this is what I am looking for, except I would like it to format the
cell after they enter the information. The reason I am doing this: I am
creating a database for an insurance broker. Within the plan designs, there
are both dollars and percentages ($35.00 copay) or (80% covered) within a
field. When it shows up on the form, I would like it to pull the percentages
and format them as a percentage and the same with the currency fields.
I tried it in the OnCurrent Event for the form:
If Me.DedSingPDIn <= 1 Then
Me.dedsinPDIn = Format(Me.DedSingPDIn, "0.00%")
Else
Me.DedSingPDIn = Format(Me.DedSingPDIn, "$#,###.00")
End If
It doesn't seem to work. Is there a way that I can do this without creating
another field for reference? There are portions of the form that will be
entered and the others pull from a table.