I’m trying to make an Access report look nice. I want to:
(1) Conditional formatting works in Excel but I haven’t been able to get it to work in Access. I can change all zeros to take the background colour thereby hiding them, but as number formatting and the Mod function don’t seem to exist in Access I can’t use “=MOD([Field],1)=0” (plus number format to show zero decimal places) and “=MOD([Field],1)<>0” (plus number format to show decimal places).
(2) Setting an object's format properties to “#.000;-#.000;"";""” works but the whole numbers end up with decimal places and you end up with trailing zeros in the decimals.
(3) Using a formula within an object's data property (eg “=IIf(Int([Field])=[ Field],Format([Field],"#"),Format([Field],"#.000"))” leaves the decimals with trailing zeros.
Which leaves me wondering if a VBA function is the best option. But I can’t get this to work. Here’s what I have (doesn’t work and would also leave decimal numbers with trailing zeros).
(Incidentally, I have to chose a variant data type instead of double as it otherwise gives me a type mismatch error.)
Am I on the right track? Is this even possible? Any suggestions would be appreciated.
- hide zeros
- show whole numbers as whole numbers only (3 not 3.000), and
- show numbers with decimals but without any trailing zeros (3.5 not 3.500).
(1) Conditional formatting works in Excel but I haven’t been able to get it to work in Access. I can change all zeros to take the background colour thereby hiding them, but as number formatting and the Mod function don’t seem to exist in Access I can’t use “=MOD([Field],1)=0” (plus number format to show zero decimal places) and “=MOD([Field],1)<>0” (plus number format to show decimal places).
(2) Setting an object's format properties to “#.000;-#.000;"";""” works but the whole numbers end up with decimal places and you end up with trailing zeros in the decimals.
(3) Using a formula within an object's data property (eg “=IIf(Int([Field])=[ Field],Format([Field],"#"),Format([Field],"#.000"))” leaves the decimals with trailing zeros.
Which leaves me wondering if a VBA function is the best option. But I can’t get this to work. Here’s what I have (doesn’t work and would also leave decimal numbers with trailing zeros).
Code:
Public Function WholeNumDec(DataNum As Variant) As Variant
Dim str1 As String
Dim str2 As String
str2 = "#;-#;"""";"""""
str1 = "#.000;-#.000;"""";"""""
If Int(DataNum) = DataNum Then
DataNum = Format(DataNum, str1)
Else
DataNum = Format(DataNum, str2)
End If
End Function
(Incidentally, I have to chose a variant data type instead of double as it otherwise gives me a type mismatch error.)
Am I on the right track? Is this even possible? Any suggestions would be appreciated.