Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Calculator on multiple forms
David McAfee 
    
3 years ago
Hi folks! I am using Rich's calculator in my DB it works great on one form but I would like to use it on as many as fourteen forms. The code below is from his video. I don't want to have to create fourteen calculator forms (named differently) if I can avoid it.

Private Sub Form_Close()
    If Not IsNull(Calc) And Not IsNull(TempVars("CalculatorFieldReturn")) And _
        Not IsNull(TempVars("CalculatorFormReturn")) Then
            'set value in form that called calculator
            
            Forms!BridgesF!CompsTsubform.Form!Quantity = Calc
    End If
End Sub
Adam Schwanz  @Reply  
           
3 years ago
You could add a hidden textbox to the calculator form. Then when you open the calculator, set a value to that hidden textbox from  whatever button/form opened the calculator. Then make an if/then statement

If HiddenTextBox=1 Then
Forms!CustomerF!Qty = Calc
ElseIf HiddenTextBox=2 Then
Forms!ContactF!Qty = Calc
etc...
David McAfee OP  @Reply  
    
3 years ago
Thanks Adam! Am I correct in assuming the code you wrote is to replace the line:
Forms!BridgesF!CompsTsubform.Form!Quantity = Calc

I will try it and let you know.
Adam Schwanz  @Reply  
           
3 years ago
Yep
Scott Axton  @Reply  
        
3 years ago
Adam - What?!!  No TempVars to set Calling Form?
Adam Schwanz  @Reply  
           
3 years ago
Missed opportunity Scott =( lol
David McAfee OP  @Reply  
    
3 years ago
Adam, I'm not sure how to set the value from the command button to start the calculator. This is the button:

Private Sub CalcBtn_Click()

    DoCalculator ("Quantity")
    
    
End Sub
Adam Schwanz  @Reply  
           
3 years ago
Oh is this a global module? I thought it was a form.

If this is from Richards Calculator 7 video, it looks like he already has tempvars setup to return it to the form that opened it. You shouldn't need to do anything extra if you are using that. Is that the one you're using?
Kevin Robertson  @Reply  
          
3 years ago
Adam Unfortunately the code as it is doesn't work with Subforms.
Would probably make a great follow up video to the Calculator series.
Adam Schwanz  @Reply  
           
3 years ago
Oh, I'll see if Richard wants to make a video on it before I post a solution.
David McAfee OP  @Reply  
    
3 years ago
Yes, I'm using it in a subform (about fourteen of them). I'd love to be able to not use the calculator, but the calculations would be too complex with so many variables.
Adam Schwanz  @Reply  
           
3 years ago
Note this is setup under the assumption that your subforms control name is the same name as the name of the form (the subform source object), was trying to automate as much as possible without having to manually send unique names for every button.

Step1
Modify the GlobalMod for DoCalculator, we need to send the FormName and ParentForm as well if neccessary

Public Function DoCalculator(FormName As String, FieldName As String, Optional ParentFormName As String)
  
    If Nz(ParentFormName, "") <> "" Then
    TempVars("CalculatorParentFormReturn") = ParentFormName
    End If
  
    TempVars("CalculatorFormReturn") = FormName
    TempVars("CalculatorFieldReturn") = FieldName
    DoCmd.OpenForm "CalculatorF"
  
End Function


Step 2
Modify the on click for buttons in a subform. Make a vba on click event in the code editor, didn't test if it works typed directly in like it is in the video (I don't think it will) Also don't send the parent form if it is not a subform, leave it blank

No Subform
    DoCalculator Me.Name, "FamilySize"
Subform
    DoCalculator Me.Name, "FamilySize", Me.Parent.Name

Step 3
Modify the on close event of the CalculatorF adding onto this section
            
If Not IsNull(TempVars("CalculatorParentFormReturn")) Then
Forms(TempVars("CalculatorParentFormReturn")).Controls(TempVars("CalculatorFormReturn")).Controls(TempVars("CalculatorFieldReturn")) = Calc
TempVars("CalculatorFormReturn") = Null
TempVars("CalculatorFieldReturn") = Null
TempVars("CalculatorParentFormReturn") = Null
Else
Forms(TempVars("CalculatorFormReturn")).Controls(TempVars("CalculatorFieldReturn")) = Calc
TempVars("CalculatorFormReturn") = Null
TempVars("CalculatorFieldReturn") = Null
End If

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

Next Unseen

 
New Feature: Comment Live View
 
 

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 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/7/2026 2:26:29 AM. PLT: 0s