Results 1 to 6 of 6
  1. #1
    Sparkydog is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    18

    Module Problem and/or How to Get a Specific Query to Process Before Another

    Hi everyone I need some help again. I am not good with VB and modules so hopefully I am making a rookie mistake.

    I am using some VB code I found on the web to assign a "Priority Code" to a list of Jobs. (The code is creating a numeric series.) Here's the code:
    Click image for larger version. 

Name:	VB Code.JPG 
Views:	7 
Size:	34.3 KB 
ID:	33468

    Here's it called out in a query where the results are what I want:
    Click image for larger version. 

Name:	Priority Query Expression1.JPG 
Views:	7 
Size:	29.4 KB 
ID:	33469

    Here is the query from above when run - gives me exactly what I want (Note job#64782-C is assigned priority #1 - this is correct.):


    Click image for larger version. 

Name:	Priority Works.JPG 
Views:	7 
Size:	48.0 KB 
ID:	33470

    But when I join that query with another, the priority no longer works the way I want. Is there a way to have the "good" query run first before running the one it's joined to?
    Click image for larger version. 

Name:	Not Working When Joined.JPG 
Views:	7 
Size:	37.8 KB 
ID:	33471

    And here is the joined query (that produces the wrong result) SQL code:
    SELECT [Active Jobs Query].Job, [Dispatch Priority4 Query].PriorityKey, [Dispatch PO5 Query].MatlStat, [Dispatch PO5 Query].Due, dbo_Job.Part_Number, dbo_Job.Description AS PNDescrip, [Combo Jobs2 Query].[CNCWC Count], [Combo Jobs2 Query].[TtlCNC Ops], [SawOP1 Query].SawStatus, dbo_Job_Operation.Sequence, dbo_Job_Operation.Work_Center, Left([work_center],3) AS WCTrim, dbo_Job_Operation.Operation_Service, dbo_Job_Operation.Description AS OPDescrip, dbo_Job_Operation.Status AS OpStatus, dbo_Job_Operation.Sched_Start, dbo_Job_Operation.Sched_End, dbo_Job.Make_Quantity, dbo_Job_Operation.Run_Qty, dbo_Job_Operation.Est_Setup_Hrs, dbo_Job_Operation.Est_Run_Hrs
    FROM (((((([Active Jobs Query] INNER JOIN dbo_Job_Operation ON [Active Jobs Query].Job = dbo_Job_Operation.Job) INNER JOIN [CNC Work Centers] ON dbo_Job_Operation.Work_Center = [CNC Work Centers].[CNC WC]) INNER JOIN dbo_Job ON [Active Jobs Query].Job = dbo_Job.Job) INNER JOIN [Combo Jobs2 Query] ON [Active Jobs Query].Job = [Combo Jobs2 Query].Job) LEFT JOIN [SawOP1 Query] ON [Active Jobs Query].Job = [SawOP1 Query].Job) LEFT JOIN [Dispatch PO5 Query] ON [Active Jobs Query].Job = [Dispatch PO5 Query].Job) LEFT JOIN [Dispatch Priority4 Query] ON [Active Jobs Query].Job = [Dispatch Priority4 Query].Job
    WHERE (((Left([work_center],3))="mil" Or (Left([work_center],3))="lat" Or (Left([work_center],3))="saw") AND ((dbo_Job_Operation.Status)<>"C") AND ((dbo_Job_Operation.Sched_Start)<=[cutoff date]))
    ORDER BY [Active Jobs Query].Job, dbo_Job_Operation.Sequence;

  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,518
    Unless I'm misreading, that just returns a sequential number. It would follow whatever the sort order of the query is.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Sparkydog is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    18
    So is there a way to assign the module to a specific query?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    What's the sort on the first query? If the goal is to assign priority numbers to specific jobs based on some criteria, the function should probably take that into account.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Sparkydog is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jan 2018
    Posts
    18
    This is the sort order of the "good" query - the one that works when I just run it alone. Yes there is a complex formula that creates an long text string of concatenated dates and other things that builds the priority order - but it is to complex to display to a user on a report. Hence the need for the autonumber function that generates a simple integer.
    Click image for larger version. 

Name:	Sort Order.JPG 
Views:	6 
Size:	34.9 KB 
ID:	33473

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Interesting, as the priority field in the first query appears to contain the same thing. I'd probably try a DCount() directly in the query, or a recordset in a function that counted the number of items with a priority less than or equal to the current one. For example directly in the query:

    PriorityKey: DCount("*", "DispatchPriority3Query", "Priority <= '" & Priority & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 6
    Last Post: 10-04-2017, 06:18 PM
  2. Problem with specific query returns
    By rebfein in forum Queries
    Replies: 4
    Last Post: 08-04-2016, 12:50 PM
  3. VB Editor won't open specific Class Module in Access 2007.
    By IncidentalProgrammer in forum Programming
    Replies: 1
    Last Post: 02-16-2015, 11:23 AM
  4. Specific Update Query Problem
    By McArthurGDM in forum Queries
    Replies: 6
    Last Post: 10-09-2014, 01:23 PM
  5. Module Problem
    By kwooten in forum Modules
    Replies: 9
    Last Post: 06-13-2012, 10:21 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