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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Equivilent to DAO CreateQueryDef method?

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I have the following code:
Dim db as DAO.Database
Dim qdf as DAO.QueryDef
Set db = CurrentDb
Set qdf = db.CreateQueryDef(strName, Me.txtSQL)

I want to accomplish the same, but in ADO. How is this done?? James Goodman
 
You'll need to use the ADOX library (Active Data Objects for DDL & Security refence).

I haven't done this but this code snippet from Help should be in the ballpark (without the parameter stuff):

[tt]
Sub CreateProcedure()

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim prm As ADODB.Parameter
Dim cat As New ADOX.Catalog

' Open the Connection
cnn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\Microsoft Office\" & _
"Office\Samples\Northwind.mdb;"

' Create the parameterized command (Microsoft Jet specific)
Set cmd.ActiveConnection = cnn
cmd.CommandText = "PARAMETERS [CustId] Text;" & _
"Select * From Customers Where CustomerId = [CustId]"

' Open the Catalog
Set cat.ActiveConnection = cnn

' Create the new Procedure
cat.Procedures.Append "CustomerById", cmd

End Sub

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top