Executing query

J

John

Hi

I have an insert query string as below. How can I execute it in word vba
uisng DAO?

Dim sSQL As String
sSQL = "INSERT INTO clients ([ClientName], [Address]) "
sSQL = sSQL & "VALUES('John Smith', '333 Park Avenue')"

Thanks

Regards
 
P

Perry

While having a reference open in yr Word VBA project to the
DAO library, here's an example in it's most simplest form:

Dim db As DAO.Database
Set db = DAO.OpenDatabase("c:\temp\db1.mdb")
db.QueryDefs("AppQryFruits").Execute

Whereby AppQryFruits is a append query (INSERT INTO)

Krgrds,
Perry
 
P

Perry

To make things complete, I've added some other
things to match my example to your's.

Dim db As DAO.Database
Dim sSQL As String
sSQL = "INSERT INTO clients ([ClientName], [Address]) "
sSQL = sSQL & "VALUES('John Smith', '333 Park Avenue')"

Set db = DAO.OpenDatabase("c:\temp\db1.mdb")
With db.QueryDefs("MyQuery")
.SQL = sSQL
.Execute
End With

Note: MyQuery needs to be a valid querydef object in yr Access database.

Krgrds,
Perry

Perry said:
While having a reference open in yr Word VBA project to the
DAO library, here's an example in it's most simplest form:

Dim db As DAO.Database
Set db = DAO.OpenDatabase("c:\temp\db1.mdb")
db.QueryDefs("AppQryFruits").Execute

Whereby AppQryFruits is a append query (INSERT INTO)

Krgrds,
Perry

John said:
Hi

I have an insert query string as below. How can I execute it in word vba
uisng DAO?

Dim sSQL As String
sSQL = "INSERT INTO clients ([ClientName], [Address]) "
sSQL = sSQL & "VALUES('John Smith', '333 Park Avenue')"

Thanks

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top