Free Lessons Courses Seminars TechHelp Fast Tips Templates Topic Index Forum ABCD

 Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon More... What's New? Popular Links ------------ Access Courses Access Index Access TechHelp Access Forum Access Troubleshooter Access Developer Network ------------ Excel Courses Excel Index ------------ Code Vault Testimonials Tip Jar Advice for Consultants

 Home > TechHelp > Directory > Access > Calculator 7 < DoEvents | Format Currency >
 Back to Calculator 7    Comments List
 Richard Pitassy         12 months ago
Is it possible for the Calc field to return a result with the number of decimal places I choose?  Formatting the calc field does not do the trick?
 Kevin Robertson             12 months ago It sure is. I added a text box (or you could use a combo box) called DecPlaces and set the Default Value to 0. I then modified the code: ```If Not IsNumeric(DecPlaces) Then DecPlaces = 0 If InStr(DecPlaces, ".") <> 0 Then DecPlaces = Int(DecPlaces) Calc = FormatNumber(Eval(Calc), DecPlaces)```
 Richard Pitassy         12 months ago Great!  Thanks Kevin.
 Gary Becker        12 months ago Can you say where you put this modified code the decimal places?
 Richard Pitassy         12 months ago Works great.
 Kevin Robertson             12 months ago In the DoCalc Sub Routine on the Calculator form. Modify the line that is already there (Calc = Eval(Calc)) with the FormatNumber as above. Add the 2 If statements above that line.
 Richard Pitassy         12 months ago Gary:  It goes behind BtnEval (Equal button).  w. Private Sub BtnEqual_Click() On Error GoTo MyErr     If IsNull(Calc) Then Exit Sub     Calc = Replace(Calc, "'", "/")     Calc = Replace(Calc, "x", "*")           If Not IsNumeric(DecPlaces) Then DecPlaces = 0      If InStr(DecPlaces, ".") <> 0 Then DecPlaces = Int(DecPlaces)      Calc = FormatNumber(Eval(Calc), DecPlaces)      Exit Sub      MyErr:     Calc = "Error!"     Calc.ForeColor = vbRed     Beep     Resume Next      End Sub

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Calculator 7.