2 display formats for 1 control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I have a textbox, Qty, which control source points to a field which contains both percentage values and integer values. In my report, I would like to display the field in the Percent format(If field is a decimal value) and all integer values will be displayed in the General Number format.

Is this possible in Access 2003?

Thanks!
 
yann said:
I have a textbox, Qty, which control source points to a field which contains both percentage values and integer values. In my report, I would like to display the field in the Percent format(If field is a decimal value) and all integer values will be displayed in the General Number format.


In the section containing the text box, I'll name it
txtNmbr. Make this text box invisible.

Add a new, unbound text box where you want to display the
specially formatted number, let's name this on
txtFormattedNmbr.

Then add some VBA code to the section's Format event
procedure:

If Me.txtNmbr = Int(Me.txtNmbr) Then
' It is an integer
txtFormattedNmbr = Format(Me.txtNmbr ,"General")
Else
' It is a percent
txtFormattedNmbr = Format(Me.txtNmbr ,"Percent")
End If

You'll probably also have to tweek some properties (e.g.
Align) to get it exactly the way you want.
 

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

Back
Top