Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
  1. #16
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20

    then its not correct, the table that you have shown is correct, but the values will remain same even if the vehicle is changed, how can you change vehicle type in sub query during execution

    Code:
    identification_code	repair_schedule	type_of_vehicle	part_no	qty_to_use	available_qty	Earmarked
    b001	2015	bike1	abc-111	2	20	4
    b001	2015	bike1	abc-112	3	30	6
    b001	2015	bike1	abc-113	1	10	2
    Code:
    identification_code	repair_schedule	type_of_vehicle	part_no	qty_to_use	available_qty	Earmarked
    b003	2014	bike2	xyz-001	2	21	0
    b003	2014	bike2	xyz-002	1	11	0

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    Try nesting the queries for an all-in-one:

    SELECT inventory.vehicle_type, inventory.part_no, inventory.available_qty, sum_query.SumOfqty_to_use
    FROM inventory INNER JOIN
    (SELECT BOM.vehicle_type, BOM.part_no, Sum(BOM.qty_to_use) AS SumOfqty_to_use
    FROM (vehicle_identification INNER JOIN repair_schedule ON vehicle_identification.identification_code = repair_schedule.identification_code) INNER JOIN BOM ON vehicle_identification.vehicle_type = BOM.vehicle_type
    WHERE (((repair_schedule.repair_schedule)<2015))
    GROUP BY BOM.vehicle_type, BOM.part_no
    HAVING (((BOM.vehicle_type)=[input vehicle type]))) As sum_query ON (inventory.part_no = sum_query.part_no) AND (inventory.vehicle_type = sum_query.vehicle_type);

    You will have to type this in the SQL view window.
    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. #18
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    Wish you a very happy new year 2012

    the query does not work if you change the input to bike2

  4. #19
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    These are the outputs I get.

    Result with 'bike1' input.
    Code:
    vehicle_type part_no available_qty SumOfqty_to_use
    bike1 abc-111 20 4
    bike1 abc-112 30 6
    bike1 abc-113 10 2
    Result with 'bike2' input.
    Code:
    vehicle_type part_no available_qty SumOfqty_to_use
    bike2 xyz-001 21 2
    bike2 xyz-002 11 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. #20
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    in the second query you should get sumofqty as 0 because there are no vehicles off the same category for repairs ahead of this one in 2014. So no quantitis will be allocated. Check table above

  6. #21
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    I solved the problem, I was trying to use the main query values in the sub query rather than vice versa i.e. the value of the sub query in the main query. this solved the problem.

    the final query is as under


    SELECT BOM.part_no, BOM.qty_to_use, inventory.available_qty, (Sum(BOM.qty_to_use)-BOM.qty_to_use) AS Earmarked
    FROM inventory INNER JOIN ((vehicle_identification INNER JOIN repair_schedule ON vehicle_identification.identification_code = repair_schedule.identification_code) INNER JOIN BOM ON vehicle_identification.vehicle_type = BOM.vehicle_type) ON inventory.part_no = BOM.part_no
    WHERE (((BOM.vehicle_type)=(SELECT vehicle_identification.vehicle_type
    FROM classification INNER JOIN vehicle_identification ON classification.type_of_vehicle = vehicle_identification.vehicle_type
    WHERE (((vehicle_identification.identification_code)=[id : ])); )) AND ((repair_schedule.repair_schedule)<=[year :]))
    GROUP BY BOM.part_no, BOM.qty_to_use, inventory.available_qty;


    this gives the results as required
    using Identification code b003(bike2) i get the table

    Code:
    part_no	qty_to_use	available_qty	Earmarked
    xyz-001	2	21	0
    xyz-002	1	11	0
    this gives the results as required
    using Identification code b001(bike1) i get the table

    Code:
    part_no	qty_to_use	available_qty	Earmarked
    abc-111	2	20	4
    abc-112	3	30	6
    abc-113	1	10	2

  7. #22
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    how to use the above query in a form with combo's and subform

    wherein combo's will provide for the input


    * how to use link fields for sub query

    regards
    ramesh

  8. #23
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    You want to refer to comboboxes for input parameters?

    WHERE vehicle_identification.identification_code=Forms!f ormname!IDcomboname AND repair_schedule.repair_schedule<=Forms!formname!Ye arcomboname
    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.

  9. #24
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    should i place this query in the visual basic code

  10. #25
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    i was using this code its givin me errors
    strsql =above query
    me.subform.sourceobject =strsql


    instead of [id:] i changed the code using """ & combo.value & ”””
    For date #" & combodate.value & "#

  11. #26
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    Not clear to me if you are asking for assistance or telling us you solved the issue.
    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.

  12. #27
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    when i was using this as query i was getting errors i even tried
    form.subform.form.recordsource = strsql
    still was getting errors i mentioned the above as it was the way i was using the code. Is there something wrong with it

    error : object name 'TableName' you entered doesn't follow Microsoft Office
    Access object-naming rules.

  13. #28
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    I don't understand what you are trying to do. Can you provide project? I will analyze your efforts.
    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.

  14. #29
    ramesh_ndyd is offline Novice
    Windows 7 32bit Access 2003
    Join Date
    Dec 2011
    Posts
    20
    i have attached the sample database with the form. pls suggest the correction.

  15. #30
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    Can't set the SourceObject property of a subform container control to just an SQL statement. It must be an Access object (table, query, form, report). Then the code can apply filter to the object or set RecodSource property of the form or report. I have never set a table or query as a SourceObject.
    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.

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

Similar Threads

  1. Update Query: Modifying Data Using Top Values
    By William McKinley in forum Queries
    Replies: 1
    Last Post: 11-30-2010, 02:20 PM
  2. Replies: 3
    Last Post: 11-26-2010, 12:38 PM
  3. Replies: 7
    Last Post: 11-13-2010, 08:08 AM
  4. Query Table Values in Append Query
    By AKQTS in forum Queries
    Replies: 5
    Last Post: 11-12-2010, 03:58 PM
  5. Replies: 3
    Last Post: 06-02-2009, 09:51 AM

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