Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a query using SQL statement

Status
Not open for further replies.

asimasm

Programmer
Nov 27, 2000
62
AU
Hello
I want to create a Query in Access using a query. I mean just like a Create Table statement wt would be the statement for Creating a Query in Access db. I have used it in SQL server using the statement Create View but cant seem to figure out wt it would be in Access and the Access Help is not of any help. I will be waitng fo reply.

Thanks
 
I've done it in VB before now, with a query definition like this:

Set dbs = OpenDatabase(strdbPath)

' Delete any existing QueryDef object with same name.

On Error Resume Next
dbs.QueryDefs.Delete "ArchiveDraw"

Set qdf = dbs.CreateQueryDef("ArchiveDraw")
qdf.SQL = "INSERT INTO Historic_Draws SELECT * FROM Current_Draw WHERE Current_Draw.Sold = 'Y';"

' Execute query.
qdf.Execute

' Return number of affected records.
lngReturn = qdf.RecordsAffected

qdf.Close
Set qdf = Nothing

Hope it helps....
 
thnaks TomKane but i need a solution using a query i.e using a DDL statement. I already have solution from VB but mine is by using ADOX object. Below is the working for it. Which may be some help to u as well.

Dim m_NewCat As New ADOX.Catalog
Dim m_Command As New ADODB.Command

m_NewCat.ActiveConnection = MyAppConnection

TableName ="MyQueryName"

'Drop Original Query First
m_NewCat.Views.Delete TableName

'Create the new Query
m_Command.CommandText = "Select * From TblXyz" m_NewCat.Views.Append TableName, m_Command

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top