Jumat, 05 Desember 2025

Re: [MSAccessProfessionals] Conditional Number formating

Hi Jane,

 

In some cases, it is OK to store a number as text, and then use it in numerical calculations. VBA or the Access Expression Service (if using a query) will do the type coercion for you.

Example:

Dim d As Double

Dim s As String

s = "10.50"

d = s + 1

Debug.Print d

 

This will print the number 11.5

 

You can also write the calculation as:
d = CDbl(s) + 1

This makes the type coercion explicit. That would be my preference.

 

If for some reason this is not good enough for you, then consider adding a text field to the table for the user-entered string, and turn the current numeric field into a Calculated field with the expression:
CDbl([yourTextField])

 

Best Regards,

 

-Tom van Stiphout.

Microsoft Access MVP

 

From: MSAccessProfessionals@groups.io <MSAccessProfessionals@groups.io> On Behalf Of Jane via groups.io
Sent: Friday, December 5, 2025 8:19 AM
To: MSAccessProfessionals@groups.io
Subject: [MSAccessProfessionals] Conditional Number formating

 

Hi

I have a numeric field (double), which I need to save/ display exactly according to how the user entered it.  I don't want to change it to a text field as the system does use it for calculations. Also general formatting to 2dp for example will show all numbers the same. 

eg 

User Enters

Currently Displays

Required Display

10.50

10.5

10.50

11

11

11

10.0

10

10.0

 

Any suggestions?

Many thanks

Jane

Tidak ada komentar:

Posting Komentar