Results 1 to 6 of 6

Error message - "# of columns in two selected tables or queries of a union query do not match"

  1. #1
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    218

    Error message - "# of columns in two selected tables or queries of a union query do not match"

    I created a couple of queries - then use VBA to loop through the queries using this code

    Code:
    SQ = "SELECT count(*)"
    SQ = SQ & " FROM (SELECT DISTINCT g" 
    SQ = SQ & " FROM " & aR(indx) & ")"
    
    Set RCDset = db.OpenRecordset(SQ)

    Where aR is an array that stores all the query names (there are 4), and indx is the index of the array.

    It works for the first two rounds but when it hits like the 2 index (which is the next query) in the array -
    error message - "The number of columns in the two selected tables or queries of a union query do not match"



    Error always occured at Set RCDset = db.OpenRecordset(SQ)

    Please advise !!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    41,906
    Post rest of the procedure. Not sure what you mean by 'index of the query'.
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window, click Go Advanced below the Quick Reply window.
    If any suggestion resolves your issue, please use the Thread Tools dropdown above first post and mark as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

  3. #3
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    218
    Sorry I meant index of the array and the array stores the name of the queries - the procedure is pretty long.

    It has two SQL statements in the VBA and one recordset. First SQL statement finds the distinct number of records of the first field for each query.
    Second SQL statement shows all the fields of each of the query. The loop is to the array that stores the query name, there are 4 query.
    the loop is to change the SQL statement - FROM clause to change to the different queries.
    Not sure if because of two SQL statement is why is giving the error message.

    But is a long procedure and is not on this machine that I am using to post here so is not so easy for me to just copy and paste over.
    But I hope you know what I mean. Error message always appear in the first query - the one I posted.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    41,906
    Any query names have spaces or special characters? Play safe and use [] in the construct.

    SQ = SQ & " FROM [" & aR(indx) & "])"
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window, click Go Advanced below the Quick Reply window.
    If any suggestion resolves your issue, please use the Thread Tools dropdown above first post and mark as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

  5. #5
    johnseito is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    218
    no space just
    _
    and
    II

    if these are consider special characters.

    Sometimes it runs all the way though and is fine but most of the time it just get stuck on that error message.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    41,906
    Not special characters.

    Have you step debugged? Exactly what are the circumstances when the code fails? What is value of the array element? What does the constructed SQL string look like?
    To provide db: Make copy, remove confidential data, run compact & repair, zip w/Windows Compression if over 500KB (2MB zip allowed), attach to post. Attachment Manager is below the Advanced post editor window, click Go Advanced below the Quick Reply window.
    If any suggestion resolves your issue, please use the Thread Tools dropdown above first post and mark as Solved!

    Debug!Debug!Debug! http://www.cpearson.com/excel/debug.htm

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

Similar Threads

  1. Replies: 1
    Last Post: 09-04-2014, 09:09 AM
  2. "Unknown" message error while opening a query
    By falahsalih in forum Access
    Replies: 7
    Last Post: 05-23-2014, 03:58 PM
  3. Suppress "Error" message following "Cancel = True"
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 03-23-2014, 04:40 PM
  4. Form error "the current field must match..."
    By plavookins in forum Forms
    Replies: 0
    Last Post: 04-13-2011, 06:42 AM
  5. Replies: 11
    Last Post: 11-26-2010, 09:53 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
  •  
Tech Forums: Microsoft Office Forums