?
Solved

Creating UNION Query in MS Access db

Posted on 2006-04-25
8
Medium Priority
?
253 Views
Last Modified: 2013-12-25
I have created a union query in access database, which works lovely jubley.

However what I now need to do is create this view programaticaly using Vb6 Ado connection.

The usual Create View syntax does not seem to allow union queries.

CREATE VIEW CommonTable as select a from table1 union select a from table2

error = -2147217900
Unions not allowed in a subquery.

Clearly Access supports the Union as I copied the select statement from the design view of the UNION Query I created using MS Access.
0
Comment
Question by:RussellMartin
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16534839
but access does not support CREATE VIEW ...
0
 
LVL 2

Author Comment

by:RussellMartin
ID: 16534906
Explain Your self!

In Vb (connected to an access database) this statement successfully creates a view/query

sql = "Create view RM_INSTRUCTION AS SELECT *,ID AS INSTRUCTION_UID FROM DATA"
db.Execute sql   'db is an ADODB.Connection
0
 
LVL 2

Author Comment

by:RussellMartin
ID: 16535191
Dont bother , I found the soloution here

http://www.dbforums.com/showthread.php?t=1117945
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16535951
Aha, I learned something new.
I knew about the views.append, but not that CREATE VIEW actually is supported as from some version...
good to know.

to close the question, please request a PAQ+Refund in the community support topic area
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 16536647
Also, please post the solution here.  There were two offered.
0
 
LVL 2

Author Comment

by:RussellMartin
ID: 16543286
here is the soloution

Sub stuff()
    Dim cn As adodb.Connection
    Dim cmd As adodb.Command
    Dim cat As ADOX.Catalog
   
    Set cat = New ADOX.Catalog

    cat.ActiveConnection = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=C:\Test\TICKETS.MDB;Jet OLEDBatabase Password=test"

   
    Set cmd = New adodb.Command
   
    cmd.CommandText = "Select * FROM STickets UNION Select * FROM ETickets"
   
    cat.Views.Append "Summary", cmd
End Sub
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16575436
Closed, 125 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question