5 pts.
 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: September 18, 2009  11:55 AM
UPDATED: September 21, 2009  1:51 PM

Answer Wiki:
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 Wiki Answer Submitted:  September 21, 2009  1:51 pm  by  Randym   1,740 pts.
All Answer Wiki Contributors:  Randym   1,740 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _