How do I set decimal places with VB Access

5 pts.
Tags:
Access 2000
Microsoft Access
VB
Visual Basic
I am using Access 2000 database for calibration control of measuring instruments. i.e. micrometers, calipers etc. The precision of the instruments varies and the decimal data fields in the table are set to Auto to minimize the stored values without changing the accuracy.

I want to change the number of decimal places displayed in the individual instrument report using an IF statement where the critera is controlled by the decimal precision required for the specific instrument.

So far I have not found the command to set decimal in VB let alone structue the entire IF statement.

 



Software/Hardware used:
Access 2000

Answer Wiki

Thanks. We'll let you know when a new response is added.

First, the decimal places property in the table does not indicate how many decimal places will be stored. It is only for displaying the decimal places.

To display the decimal places on the report, use the format property of the instrument field.
Here’s an example of code that could be placed in the report’s detail section On Format event:

Dim frmt As String, x As Integer, numplaces As Integer
frmt = “#.” ‘Set up the format string 1 digit in front of the decimal place
Select Case Me![Instrument]
Case “micrometer”
numplaces = 2
Case “caliper”
numplaces = 3
Case Else
numplaces = 4 ‘number of places for any other instrument not defined.
End Select
For x = 1 To numplaces
frmt = frmt & “0″
Next x
Me![InstrumentCalibration].Format = frmt

If you didn’t want to hard code the instruments, you could place the number of places for the calibration in the table that is bound to the report. Then you could do this:

Dim frmt As String, x As Integer, numplaces As Integer
frmt = “#.”
For x = 1 To me![numplaces] ‘column in table that tells how many places for that instrument
frmt = frmt & “0″
Next x
Me![InstrumentCalibration].Format = frmt

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following