How do I set decimal places with VB Access
5 pts.
0
Q:
How do I set decimal places with VB Access
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
ASKED: Sep 18 2009  11:55 AM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
1410 pts.
0
A:
 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0
  • AddThis Social Bookmark Button
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
Last Answered: Sep 21 2009  1:51 PM GMT by Randym   1410 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



0