Results 1 to 7 of 7
  1. #1
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57

    Union Queries

    SOLVED!



    Hi all,

    I need to combine results from two different forms. So I created a union query but it only returns the results of one of the tables.

    Here's what I did:

    I made a query for lead discussions with COIs
    - form: Lead Activity Report
    - fields: date of last contact, COI and comments - COI

    I then made a qury for general discussions with COIs
    - form: COI Discussion Form
    - fields: date, COI and general comments

    Fianlly, I created the union query in SQL view. See below.

    SELECT [Lead Activity Report].[Date of last contact], [Lead Activity Report].COI, [Lead Activity Report].[Comments - COI]
    FROM [Lead Activity Report]
    UNION ALL
    SELECT [COI Discussion Form].Date, [COI Discussion Form].COI, [COI Discussion Form].[Discussion points]
    FROM [COI Discussion Form];

    What did I do wrong? Your help is appreciated!

    Thanks.

    P.S. my dbase is attached

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    To create a Union Query, your fields must be named exactly the same and be in the same sequence. You will need to create an alias for the fields in one of your tables to make them match.

    Alan

  3. #3
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    I respectfully disagree with Alan. The fields don't have to be named exactly the same, but each query has to have the same number of fields....and the same data types in the matching fields.

    Your union query is working fine. You have 13 records in the lead activity report table and 1 record in the COI discussion form table.

    The overall design of your database could use some work, though.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by kennejd View Post
    The fields don't have to be named exactly the same, but each query has to have the same number of fields....and the same data types in the matching fields.
    CORRECT. But then, you already knew that didn't you kenny?

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Kenny;
    The fields don't have to be named exactly the same,
    Thanks. The great thing about forums is that if you are wrong, someone will correct you and that is a great learning experience. This is something I did not know. If you don't have the fields named the same, then what field name appears in the query result? The first one, second, third, etc. or some combination or something else?

    Alan

  6. #6
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    The field name of the first query appears in the result.

  7. #7
    tarhim47 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    57
    Thanks for your help!

    I figured out that the query is working just fine. As far as the overall dbase is concerned, it is very much in the first stage. Having said that, if you have any tips, I would welcome them.

    Thanks again.

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

Similar Threads

  1. Union Queries when Splitting Database
    By jaypoppin in forum Queries
    Replies: 3
    Last Post: 03-04-2011, 06:06 PM
  2. Union Query
    By jlclark4 in forum Queries
    Replies: 3
    Last Post: 02-25-2011, 08:21 PM
  3. Union Query Help
    By jo15765 in forum Queries
    Replies: 7
    Last Post: 01-06-2011, 05:46 PM
  4. Please help me out with union query
    By radicrains in forum Access
    Replies: 1
    Last Post: 10-29-2010, 01:48 AM
  5. Replies: 3
    Last Post: 05-21-2010, 03:57 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