Results 1 to 8 of 8
  1. #1
    tmw2912 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    3

    VB Access Basic Question


    I have two queries written in a module in Access that will open both queries. Is there a way to write code that will combine the two queries into a single output?

  2. #2
    mbar is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    12
    how about creating a 3rd query that will combine the original 2, then using code to open the 3rd query.

  3. #3
    tmw2912 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    3
    I don't think that would work. Let me try to explain in further detail to see if possible.

    Query 1 -
    Is a listing of all Employees and the information on their account. Those Employees also have people that are attached to them. The tables that I am pulling for Query 1 only give me the information for the employee themselves.

    EX:
    ID12345, John Smith, 1234 Main Street, Anytown, USA
    ID67891, Michael Johnson, 5678 3rd ST, Jamestown, Africa

    Query 2 -
    Lists information for those attached to the Primary.

    EX:

    ID12345, SUBID98765, Amanda Smith, 1234 Main Street, Anytown, USA
    ID67891, SUBID45687, Jeremy Johnson, 5678 3rd ST, Jamestown, Africa

    What I am trying to get is a combination of the two queries that would look like the:

    ID12345, SUBID98765, Amanda Smith, 1234 Main Street, Anytown, USA
    ID67891, SUBID45687, Jeremy Johnson, 5678 3rd ST, Jamestown, Africa
    ID12345, , John Smith, 1234 Main Street, Anytown, USA
    ID67891, , Michael Johnson, 5678 3rd ST, Jamestown, Africa


    Hopefully that makes more sense. Is it possible to do that?

  4. #4
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    It can be done as a third query. I'd make a Union query a subquery, then do an Order By clause to order your data for you.
    SELECT SQ1.*
    FROM (SELECT ID, "" AS SUBID, Name, Address1, City, State FROM Table1 UNION SELECT ID, SUBID, Name, Address1, City, State FROM Table2) as SQ1
    Order By ID, SubID

  5. #5
    tmw2912 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    3
    Awesome, that worked. Thanks

  6. #6
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    No offense, but I think the worst advice someone could possibly give you right now is to just keep on cruising along...and use a Union query to 'stack' data on top of each other, data that is resulting from non-normalized data.

    If you had the proper tables set up, and the proper data in those tables, you should be able to do all of it in one query, or at the very worst, a 2nd query that uses the first query as a table (but I doubt that'd be necessary).

    The best thing you can do for yourself at this point is to step back and do some re-design..truthfully.

  7. #7
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    No offense, but I don't really care to tell someone they need to completely re-organize their entire data structure which may have several thousands of rows of data in it already, just to make one simple query. Could the database possibly be re-organized for better normalization, sure. But I wouldn't say the time and effort it would take is warranted just because of one query. Perhaps the database was inherrited. Perhaps management demands it to be structured this way. Who knows. But it certainly isn't the worst advice someone can give.

  8. #8
    ipisors is offline Access Developer
    Windows XP Access 2007
    Join Date
    Sep 2013
    Posts
    119
    I suppose we can agree to disagree. I want to give out quality advice, and yes, very rarely there are situations where structures cannot be re-done. But my standpoint is, Let the OP tell you that they CAN'T do the right thing - don't jump for the lowest possible standard first off by assuming it..

    It just seems like a very, very odd perspective from an 'experienced access developer', who would see this as a major red flag and give the restructuring advice.

    But if you see the goal as finishing the query and cruising on, well then...

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

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2012, 01:09 PM
  2. Basic Question
    By za20001 in forum Queries
    Replies: 2
    Last Post: 04-11-2011, 03:59 PM
  3. basic (sorry) question
    By wokeeffe in forum Database Design
    Replies: 1
    Last Post: 12-21-2010, 11:20 AM
  4. Really basic question
    By jimlaw in forum Forms
    Replies: 1
    Last Post: 07-27-2009, 07:20 AM
  5. Basic Question
    By chris11590 in forum Forms
    Replies: 0
    Last Post: 08-04-2008, 05:57 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