Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Calculator 7 < DoEvents | Format Currency >
Back to Calculator 7    Comments List
Eval function decimal places Upload Images   Link   Email  
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.
 

 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/19/2024 11:41:40 PM. PLT: 1s