Format a value using code

  • Thread starter Thread starter KCobler
  • Start date Start date
K

KCobler

I have a form, with a combo box that pulls several values from another table.
Besides using it to populate one field "cbxBuilding", I use it to
automatically populate another field on the form "txtSF" (Square Feet). This
SF is an unbound text box.

No problem in getting the correct number. However, I seem to be unable to
format the value. I would like it in the Standard format (with a comma
separator for thousands). I will also have other cases where I just use a
text string, or a date, etc.

Here is my event code, which I have for Current and AfterUpdate events:

Private Sub cbxBuilding_AfterUpdate()
Me.tbxSF.Value = Me.cbxBuilding.Column(2)
'This assigns tbxSF with the value in column 2 that the combo list
obtains
End Sub

In summary, how do I get the code to format my value, too?

I am new to code. I appreciate very specific directions. Thank you.
(Using Access 2002.)
 
On Wed, 10 Jun 2009 17:41:01 -0700, KCobler

You can look at the Format property of that textbox (see help file for
syntax details), or you can format the value while you assign it to
the textbox:
Me.tbxSF.Value = Format(Me.cbxBuilding.Column(2), "#,###.00")

-Tom.
Microsoft Access MVP
 
Thank you, formatting using the code works great.

For some reason, however, when I use the properties format specification, it
had no effect on the number format, and this was frustrating me.

Thanks for the quick reply.
 
Back
Top