Results 1 to 10 of 10
  1. #1
    CraigR is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    27

    2 calculations based on 1 dropdown answer but using different rows from the dropdown

    I have a dropdown combo box that includes four fields and I would like to run two calculations

    I could have a dropdown1 with Membrane or No Membrane to act as a filter


    then dropdown2 with Climatic Zone A,B or C
    and then do the calculation

    However I need to give the calculation for BOTH options.

    The combo box is based on the following info
    if "no" membrane "With" membrane class
    Climatic Zone A 2000 1000 Climatzone
    Climatic Zone B 4000 2000 Climatzone
    Climatic Zone C 6000 3000 Climatzone

    Field1 dropdown combo = Climatic Zone A,B or C
    in the data section of the property sheet, in Row Source
    I have 4 rows/fields based in the info above

    Field2 is a number field that I input an area

    What I am trying to do is calculate Field1 (row2) x Field2 = answer while at the same time calculating Field1 (row3) x Field2
    so lets say I selected Climatic Zone A in Field1 dropdown and in Field2 I added 380.

    I want the calculation 2000 x 380 = 760,000 | 1000 x 380 = 380,000

    If I were doing this in excel I could use =VLOOKUP to pull the info out of each cell to run the calc's


    with thanks
    Craig

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    I cannot reconcile references to row2 and row3 with the numbers used in the calculation. Both numbers appear to be from row1. So I am confused.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CraigR is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    27
    Sorry, I haven't explained it all that well.

    The Dropdown = SELECT GeneralInfo.Item, GeneralInfo.Number0, GeneralInfo.Number1, GeneralInfo.Number2, GeneralInfo.Number3, GeneralInfo.Class FROM GeneralInfo WHERE (((GeneralInfo.Class)="Climatic Zone"));

    GeneralInfo.Item = Climatic Zone A or Climatic Zone B or Climatic Zone C
    GeneralInfo.Number0 = 2000 or 4000 or 6000 *these numbers relate to If there is a membrane on the ground then these apply*
    GeneralInfo.Number1 = 1000 or 2000 or 3000 *these numbers relate to If there is NO membrane on the ground then these apply*

    I need to calculate both sets of numbers as an option to either "membrane or no membrane"

    so if I select Climatic Zone A from the dropdown then it would calculate ([2000]*[anotherfield])=X | and ([1000]*[anotherfield]) = Y


    Normally I would go
    The Dropdown = SELECT GeneralInfo.Number0, GeneralInfo.Item, GeneralInfo.Class FROM GeneralInfo WHERE (((GeneralInfo.Class)="Climatic Zone"));
    and set columns to 0;2. So that the number would be selected but the text would be shown in the dropdown, however this would only allow for 1 calculation.

    With thanksCraig

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Your combobox RowSource does not include Number1 field, however, since it is exactly half of Number0 just divide by 2 - unless that is not always the case. Include Number1 in the RowSource query - displayed or hidden. Reference combobox columns by index. Index begins with 0. If Number2 is in column 2 the index is 1: ComboboxName.Column(1)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Join Date
    Apr 2017
    Posts
    1,679
    At start, your GeneralInfo table is not normalized, and as result, it will be difficult get normal combo - you have to use UNION query with 3 instances of your GeneralInfo table as source currently.

    Or simply redesign the table:
    GeneralInfio: ID, Item, Class, Type, Value, where in field Type you store a value indicating for class 'Climatic Zone', is there membrane on ground or not (p.e. TRUE/FALSE). ID can be autonumeric primary key, as you'll have several Items with same value in table for now and Item can't serve as PK anymore.

    Then your combo will be based on query
    SELECT DISTINCT Value, Item & Iif(Type, " with membrane on ground", " without membrane on ground") & " (" & CStr(Value) & ")" AS [SelectionInfo] FROM GeneralInfo WHERE (((GeneralInfo.Class)="Climatic Zone"))

    Set combos BoundColumn property =1, ColumnCount property to 2, and ColumnWidths property to '0,2.5' (the second number can be any positive number - the setting estimates, that the user sees SelectionInfo column from query in combo box - you may have more columns in query, but the only the first one with width > 0 is displayed.).

    The value for combo box will be Value from table GeneralInfo according your selection.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Note that "Class", "Type" and "Value" are reserved words and shouldn't be used for object names.

  7. #7
    Join Date
    Apr 2017
    Posts
    1,679
    Quote Originally Posted by ssanfu View Post
    Note that "Class", "Type" and "Value" are reserved words and shouldn't be used for object names.
    Sorry for this - I was almost sleeping when I posted this.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In the example dB, there are three methods of doing the calculation: using a subroutine, using a function or doing the calculation in the control.
    Attached Files Attached Files

  9. #9
    CraigR is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    27
    Hi Steve

    Mate THANK YOU!

    Craig

  10. #10
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Good luck with your project....

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

Similar Threads

  1. Replies: 5
    Last Post: 08-13-2014, 02:52 AM
  2. Replies: 1
    Last Post: 07-09-2014, 03:36 PM
  3. Virtually combine two rows for dropdown
    By squirrly in forum Queries
    Replies: 3
    Last Post: 01-28-2013, 03:22 PM
  4. Replies: 3
    Last Post: 08-15-2012, 06:48 AM
  5. Replies: 11
    Last Post: 05-28-2012, 05:47 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