Yes, you can. It does kind of depend on what you are doing - so can you be a little more specific as to what you need and where you are trying to use it?
You can build a sql statement in vba, yes. From there you can do a varity of things. Display the records in a listbox, set the recordsource of a subform, etc.
What exactly do you mean by "get the sql contents"?
I am trying to get the text that makes up the query. From my vb app I am connecting to my access database, I can see what queries there and can run them, but would like to be able to view the script before executing
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = OpenDatabase("C:\PathToDb.mdb")
Set qdf = db.QueryDefs("NameOfQueryHere")
YourFormName.YourTextBoxName = qdf.SQL
qdf.Close
db.Close
Set qdf = Nothing
Set db = Nothing
Thanks Bob.
I have achieved my goal with the use of interop (not ideal)
Here is the code if anyone is interested. I converted it to c# as it is my preference:
Thanks Bob.
I have achieved my goal with the use of interop (not ideal)
Here is the code if anyone is interested. I converted it to c# as it is my preference:
And I did a test where I set a reference to DAO 3.6 and then used this code successfully:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dbe As New dao.DBEngine
Dim db As dao.Database
Dim qdf As dao.QueryDef
db = dbe.OpenDatabase("C:\Temp\Test.mdb")
qdf = db.QueryDefs("qryTest")
Me.TextBox1.Text = qdf.SQL
db.Close()
db = Nothing
dbe = Nothing
End Sub