Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23

    Combining values from different forms

    I have a subform,(named 'Fldetail'), in which I would like to calculate a sales tax based on the sales price * a tax rate stored in a separate Form. This form is called 'Values' and contains the 'Tax Rate' in a row called that.

    The amount to use in the calculation is in the same row as the result to be calculated and is called 'Amount'.
    To further complicate things, the final calculation is dependent on a type field labeled 'S' (for Sales Item) in the same row and a field from the main form called 'Tax Code', (the main form is named 'Florist'), so the final calculation is:
    If 'S' and 'Tax Code' are true then the result is ('Tax Rate' * 'Amount') + 'Amount'.

    My problem is that I have not been able to determine the proper syntax to locate the 'Tax Rate' in the other form and combine it with the values from the row with 'Amount' and 'S' to produce the desired result or the appropriate 'IF' conditional.



    I have tried numerous times to solve this problem, but have failed to do so. The combination of brackets and ! signs completely baffle me.

    Any help would be greatly appreciated.

    David Wright Sr.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    I would have thought use the builder to create:

    Iif(s=true and tax code = true, tax rate * amount) + amount.

    The builder will help you pull in require info and keep syntax errors to a minimum.


    Sent from my iPhone using Tapatalk

  4. #4
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23
    Quote Originally Posted by andy49 View Post
    I would have thought use the builder to create:

    Iif(s=true and tax code = true, tax rate * amount) + amount.

    The builder will help you pull in require info and keep syntax errors to a minimum.


    Sent from my iPhone using Tapatalk
    The code says exactly what I want except that my problem is that 'S' comes from the subform, 'Tax Code' from the main form and 'Tax Rate' from a different form called Values. I can't figure out the syntax for putting these all together. I suppose that I could simplify somewhat by including 'Tax Rate' in the query for the main form.

    Thanks

    David
    P.S. I would like to put the results in a VBA procedure to execute after update of the field.
    P.P.S. (to baldy) Thanks for the link, but I had the same kind of problems interpreting how these were to be used.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by DavidWrightSr View Post
    P.P.S. (to baldy) Thanks for the link, but I had the same kind of problems interpreting how these were to be used.
    hard to say where you're going wrong without seeing what you're trying.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have a subform,(named 'Fldetail'), in which I would like to calculate a sales tax based on the sales price * a tax rate stored in a separate Form. This form is called 'Values'
    Just for clarity, forms do not "store" data. Tables store data; forms are a way to view the data stored in tables.
    "Values" is a reserved word in Access and shouldn't be used as an object name. A better name would be "frmValues".

    Is it possible for the tax rate to change?
    If yes, I would save the tax rate in the record. Otherwise, next year, if you look back at a record, the calculated value will be different if the tax rate was changed.

    Where are you doing the calculation?
    In a query? (design view or SQL view?)
    In the control source of a control?
    In VBA code?

    Are "S" and "TaxCode" boolean (T/F) fields?


    If you are in the subform, "S" and "Amount" are available in the sub form, "TaxCode" is on the main form (ie parent form) and the "Tax rate" is on a different form.
    NOTE: The form "Values" MUST be open for the calculation to work correctly.

    Code:
    Iif(s=true and tax code = true, tax rate * amount) + amount
    The syntax for the immediate if function (IIF() ) is "IIF(condition, Value if True, Value If False)"
    You are missing the FALSE part.

    The condition clause is:
    Code:
    S=TRUE and Forms!Florist.[tax code] = TRUE
    The TRUE clause is:
    Code:
    (Forms!Values.[tax rate] * amount) + amount
    The FALSE clause is: 0

    Putting it together:
    Code:
    IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0)
    If you were in the query design view, you might use
    Code:
    ExtendedAmount: IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0)
    In SQL view, you might use:
    Code:
     IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0) AS ExtendedAmount
    In the Control Source property of a control:
    Code:
    = IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0)

    If the form "Values" is not open, you might try using the DLOOKUP() function to get the tax rate.

  7. #7
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23
    Many Thanks. I'll see what I can do with all of this. It looks promising.

    David Wright

  8. #8
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23
    [From: ssanfu]Just for clarity, forms do not "store" data. Tables store data; forms are a way to view the data stored in tables.
    "Values" is a reserved word in Access and shouldn't be used as an object name. A better name would be "frmValues".

    I have changed all of my objects to reflect whether they are 'frm's , 'rpt's, 'tbl's etc.


    Is it possible for the tax rate to change?
    If yes, I would save the tax rate in the record. Otherwise, next year, if you look back at a record, the calculated value will be different if the tax rate was changed.

    Yes, I will be doing that.

    Where are you doing the calculation?
    In a query? (design view or SQL view?)
    In the control source of a control?
    In VBA code?

    I am trying to modify the SQL code in the subform design.

    Are "S" and "TaxCode" boolean (T/F) fields?

    'S' is a text field one of the designators as to the type of record, it is, e.g'Sales', 'Payment, 'Balance Forward' etc., 'TaxCode' is boolean

    If you are in the subform, "S" and "Amount" are available in the sub form, "TaxCode" is on the main form (ie parent form) and the "Tax rate" is on a different form.
    NOTE: The form "Values" MUST be open for the calculation to work correctly.

    I don't understand what you mean here by 'Open'? As I see it, the only 'open' objects are the ones on the main form and the subform. Or, is that accomplished by 'Forms!Values.[tax rate]' in the code?

    Code:
    Iif(s=true and tax code = true, tax rate * amount) + amount
    The syntax for the immediate if function (IIF() ) is "IIF(condition, Value if True, Value If False)"
    You are missing the FALSE part.

    The condition clause is:
    Code:
    S=TRUE and Forms!Florist.[tax code] = TRUE
    The TRUE clause is:
    Code:
    (Forms!Values.[tax rate] * amount) + amount
    The FALSE clause is: 0

    Putting it together:
    Code:
    IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0)
    If you were in the query design view, you might use
    Code:
    ExtendedAmount: IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0)
    In SQL view, you might use:
    Code:
     IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0) AS ExtendedAmount
    I'll try this one. One problem I haven't mentioned is that I am using Access 2000 and I don't believe that 'Iif' works there, so I am trying to create a VBA procedure to do this. You ask, "why am I using 2000"? The answer is money. If all else fails, I have to dig up the cash to purchase a later version.

    In the Control Source property of a control:
    Code:
    = IIF(S=TRUE and Forms!Florist.[tax code] = TRUE, (Forms!Values.[tax rate] * Amount) + Amount, 0)

    If the form "Values" is not open, you might try using the DLOOKUP() function to get the tax rate

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I'll let Steve address your responses to his post, but IIf() definitely works in A2000.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23
    Thanks. I hadn't tried it myself, but was going by a page I was looking at that said support only went back to version 2003. "Everything you read on the internet is true".

    Thanks very much.

    David

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. Did I mention I was abducted by aliens?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23
    [To: ssanfu] (I am assuming that this is Steve who pbaldy referred to.)

    I tried the following: (I left off the 'S' text to make it simpler)

    =IIf(Forms!frmFlorist.[Tax Code]=True,(Forms!frmValues.[Tax Rate]*[Amount]+[Amount]))

    The result was still a #NAME? error.

    Still don't understand about having frmValues Open.

    Should the [Tax Code] and [Tax Rate] come from the field's control source or from the name?

    Sorry to be such a pain.

    David

  13. #13
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Sorry to cut in here but you've no false for your iif statement.

    What do you want in the textbox if there is [tax code]= false?

    Try putting "false" or "" between the last two )) to see if this helps.




    Sent from my iPhone using Tapatalk

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't understand what you mean here by 'Open'? As I see it, the only 'open' objects are the ones on the main form and the subform.
    Still don't understand about having frmValues Open.
    A form is OPEN if it is loaded in memory; it can be visible or hidden. If a form is not open, you cannot get values from it.


    Or, is that accomplished by 'Forms!Values.[tax rate]' in the code?
    Yes, but ONLY IF the form is open.
    You use "Forms!Values.[tax rate]" to refer to a control named "[tax rate]" on a form named "Values" to get a value.


    Should the [Tax Code] and [Tax Rate] come from the field's control source or from the name?
    Since you are going to store the tax rate in the record, you will just use the field name [Tax Rate]. (much easier)
    And since the [Tax Code] is on the main form, you will still need to refer to the control like this: Forms!Florist.[tax code] ...


    You say "S" is a text type field, so try:
    If you were in the query design view, try:
    Code:
    ExtendedAmount: IIF([S]="Sales" and Forms!Florist.[tax code] = TRUE, ([tax rate] * Amount) + Amount, 0)
    In SQL view, try:
    Code:
     IIF([S] = "Sales" and Forms!Florist.[tax code] = TRUE, ([tax rate] * Amount) + Amount, 0) AS ExtendedAmount


    I am trying to modify the SQL code in the subform design.
    If you still have problems with the SQL, post the SQL of the sub form.






    Some suggestions:
    ------------------------------
    Use only letters and numbers (exception is the underscore) for object names. (especially field names)
    -> Do not use spaces, punctuation or special characters in object names!!! (the name [tax rate] is BAD because it has a space)
    - Do not begin object names with a number.
    - Better to not use look up FIELDS, multi-value fields or calculated fields in tables.

  15. #15
    Join Date
    Oct 2016
    Location
    Chatsworth, GA (Northwest corner of state)
    Posts
    23
    I have still not resolved this problem, but it is necessary for me to revisit it.
    Let me make it clearer what I am trying to do.


    1. I have a subform showing in datasheet format.

    In addition to any existing records, the last record is a blank one which can be filled in to create a new record It contains the following fields.

    1. Acctno [the key field which ties the subform to ID on the main form]
    2. Date [filled in automatically to contain the current date.]
    3. Type [a Field which determines what type of record is contained.]

    This can be ‘S’ for Sales, ‘P’ for Payment, ‘B’ for Balance Forward.”S” is automatically in as this is the most common action.]

    1. Amount [The dollar amount of the transaction.]
    2. Tax. [The calculated tax for any “Sales”]. Empty for other Types.

    f) Description [A descriptive text for the transaction, e., “Flower Arrangement”, “Payment” etc.

    2) The complete calculation for Tax depends on
    a) Having an ‘S’ in Type
    b) A taxcode in the main form. The default is ‘True’ for tax being applied. ‘False’ for No Tax.
    c) An amount being entered.
    d) A tax rate from a Form called ‘Values.[tax rate].

    The full calculation that I envision is:
    The Tax result = [tax rate] * Amount provided that [Taxcode]=false and Type=”S”. (This obviously a pseudo code since I have not been able to create valid code to solve the problem.

    I have tried a very simple version, just to check what I think should work by trying by using the value .07 as tax rate, and eliminating the Type and Tax Code provisions to calculate [tax] as .07*[Amount]. I tried this on both entering and exiting the tax field, but nothing happens. =[tax]=.07 * [Amount] produces no results.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Combining combobox values to one value
    By DanielleN in forum Access
    Replies: 3
    Last Post: 08-30-2016, 01:12 PM
  2. Combining values in the same field
    By Sidran in forum Access
    Replies: 4
    Last Post: 07-31-2014, 11:10 PM
  3. Combining count values for a pie chart
    By wlkr.jk in forum Queries
    Replies: 4
    Last Post: 06-10-2014, 06:21 AM
  4. Combining two boolean values
    By John_B in forum Access
    Replies: 6
    Last Post: 02-11-2012, 11:45 AM
  5. Replies: 12
    Last Post: 07-18-2011, 12:47 PM

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