Link to home
Start Free TrialLog in
Avatar of RussellMartin
RussellMartinFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Creating UNION Query in MS Access db

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.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

but access does not support CREATE VIEW ...
Avatar of RussellMartin

ASKER

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
Dont bother , I found the soloution here

http://www.dbforums.com/showthread.php?t=1117945
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
Also, please post the solution here.  There were two offered.
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
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial