The union comes back with an error that the column count doesn't match.
Main Topics
Browse All TopicsI have a crosstab where the number of the month is the column heading. I need to union this query with another... however, they both don't have all 12 months. How can I make it work automatically? (I realize I could cheat and make another query where I add the other month columns... but I would have to change that every month)
Thanks,
Doug
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
That's easy.
You need to construct query of the following type
SELECT [1], [2], 'empty_column_data' AS [3], ..., 'empty_column_data' AS [12] FROM table1
UNION ALLL
SELECT [1], 'empty_column_data' AS [2], ..., 'empty_column_data' AS [12] FROM table2
where empty_column_data - data which will be filled in column absent in original table1, table2, etc
you can construct this query using VBA, but you have to know which columns you don't have in each table.
For now, however, I don't know how to determine if column exists in the table (I couldn't locate that information in MSysObjects table). But you can always use multiple statements
On Error GoTo ErrorLabel
SELECT columnname FROM table
Just bring up the properties of the query (open the query in design view, click in the upper portion of the window and click View->Properties). You can then set the Column Headings property to:
"01","02","03","04","05","
That should force the query to return 12 columns regardless of its source data. Do this for both queries and you should then be able to union them.
Business Accounts
Answer for Membership
by: JezWaltersPosted on 2003-04-15 at 09:08:32ID: 8334793
What about UNIONing your UNION with a query that selects records from a (static) table that contains a null record for each month?