Results 1 to 14 of 14
  1. #1
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15

    Question Mini-Calculator on a form


    Hi, I found this little thing on the internet, it work nicely when stands alone, problem is when I put it on my form, next to a field (Order_Amount), it does not copy value from calculator to the field. Can some one tell me what should I do?
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    It works perfectly. I dont see a problem. I clickd the button beside the text box, the calc opened, i calcd, it pasted.
    perfect.

  3. #3
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15
    No, if you paste it on another form, it will not work as expected. That's why I am wondering

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Did you edit the click event of the button to change the name of the text box?? It worked for me.

    I created a new form (Form1).
    I added a new text box (Text0).
    I copied the button from frmShowCalc and pasted it on Form1
    I edited the click event of the button - changed it from =SelectCalculation([ShowCalcs]) to =SelectCalculation([Text0])
    Saved Form1

    Works great!

  5. #5
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15
    Steve, do you edit anything on the module? Thanks

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    do you edit anything on the module
    Nope. That is why the function has a parameter.
    Open Form1. In design view , look at the events tab for the button.

  7. #7
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15
    Steve, I think maybe the problem is because I have designed the field a little complicated: by format, it's currency; by value it is a result of calculation, something like: ProductPrice*OrderQuantity; I need the calculator only in some cases. Do you think this is the problem?

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    First - terminology. Tables have fields. Forms have controls.

    I have designed the field a little complicated: by format, it's currency
    The format property has no effect on pasting in a value.

    by value it is a result of calculation
    If a form has a control named "Order_Amount" (a text box), and the Control source property is set to "= ProductPrice*OrderQuantity", then the calculator will not work on this control.

    I need the calculator only in some cases.
    More info???

  9. #9
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15
    Quote Originally Posted by ssanfu View Post

    If a form has a control named "Order_Amount" (a text box), and the Control source property is set to "= ProductPrice*OrderQuantity", then the calculator will not work on this control.
    Yeah, in fact, I put this code on the afterupdate property of another text box, it looks like this:
    Private Sub Order_Quantity_AfterUpdate()
    Me.Order_Amount = Round(Me.Order_Quantity * Me.Product_Price)
    End Sub
    Then, call it again when Order_Amount gets focus:
    Private Sub Order_Amount_GotFocus()
    Call Order_Quantity_AfterUpdate
    End Sub
    Maybe this is why the calculator doesn't work?

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Code:
    Private Sub Order_Amount_GotFocus()
    Call Order_Quantity_AfterUpdate
    End Sub
    Every time the control gets the focus, the order amount is recalculated. Doesn't matter what you enter or how you enter data (manually or with calculator), the value you enter is overwritten.

    IMO, the "Order_Amount" should only be calculated when you enter a quantity. Should not be using the "Got Focus" event (I would delete this procedure).

    Are you saving the "Order_Amount" in a field of a table? Normally, calculated values are not saved. Having said that, I have had to save calculated values because of speed issues (calculations of amounts over thousands of records), or audit tracking.

  11. #11
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15
    Actually, as you said I have to save the calculated values for auditing purposes. Normally, it would be OK if I do "Got Focus" event. But when it comes to calculations, like special rates, I have to do calculation by hand, this is where the calculator coming handy. Not sure what to do if "got Focus" deleted? Where should I store the procedures for calculation results? At OrderQuantity's "After Update"? Thanks

  12. #12
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not sure what to do if "got Focus" deleted?
    Don't have to do anything!

    This is a bound form, right? and the control is bound to a field, right?
    Then Access automatically saves the record (or changes) if the form is "dirty" (has unsaved changes) and :
    - you move to a different record
    - you close the form
    - you re-query the form

    If you change the quantity, the after update event fires for the "Order_Quantity" control which calculates the order amount and puts the result in the "Order_Amount" control. IMO, having the procedure "Order_Amount_GotFocus()" is worthless.

    You didn't state how the price gets entered in the "Product_Price" control. I would have a "Product_Price_AfterUpdate" event that calculates the "Order_Amount", just like the "Order_Quantity" control. Price and quantity are the only two things that can affect the order amount.

    I do add the NZ() function to handle NULLs:
    Me.Order_Amount = Round(NZ(Me.Order_Quantity,0) * NZ(Me.Product_Price,0),2)

    I added the number of decimals to the round function. If you don't want cents, change the 2 to a zero.

  13. #13
    delaikhi is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    May 2014
    Posts
    15
    Quote Originally Posted by ssanfu View Post

    This is a bound form, right? and the control is bound to a field, right?
    Yeah

    Quote Originally Posted by ssanfu View Post
    You didn't state how the price gets entered in the "Product_Price" control.I would have a "Product_Price_AfterUpdate" event that calculates the "Order_Amount", just like the "Order_Quantity" control. Price and quantity are the only two things that can affect the order amount.
    The Product_Price comes from a separate table tblProductDetails, so that's kinda fixed. But the Order_Amount comes from 3 types of things: "Regular" and "Expedite), in the first case, it would be calculated like: [Order_Quantity]*[Product_Price]; in the latter case: [Order_Quantity]*[Product_Price]+20

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "Regular" and "Expedite" are only 2.

    I'm guessing this is shipping? Is "Regular" / "Expedite" stored with the order?

    You could use:

    Me.Order_Amount = Round(NZ(Me.Order_Quantity,0) * NZ(Me.Product_Price,0),2) + IIF([fieldname] = "Regular",0,20)


    Can you post the dB? Just the tables, queries and forms involved with a couple of test records.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Textbox Calculator
    By Randy in forum Access
    Replies: 10
    Last Post: 03-16-2019, 07:36 PM
  2. Button in form to open Windows Calculator
    By Aosmond in forum Forms
    Replies: 5
    Last Post: 01-15-2013, 06:17 PM
  3. Calculator
    By Azeez_Andaman in forum Access
    Replies: 1
    Last Post: 08-14-2011, 12:10 PM
  4. Excel calculator
    By warrigal in forum Database Design
    Replies: 0
    Last Post: 03-15-2011, 05:50 PM
  5. Calculator on the form?
    By Peljo in forum Access
    Replies: 0
    Last Post: 02-28-2008, 02:58 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums