INSERT INTO in VBA using a variable

R

Ronny

Why doesn't this work:


Dim WordApp As Object
Dim WordDoc As Object
Dim strActiveDoc As String

Set WordDoc = WordApp.Documents.Open(strDocName)

Dim sqlPers As String
Dim dbs As ADODB.Connection

Set dbs = Application.CurrentProject.Connection

sqlPers = "INSERT INTO Historikk VALUES WordDoc "
dbs.Execute sqlPers
dbs.Close

This works:

sqlPers = "INSERT INTO Historikk VALUES ('Testing') "


I want't the open document name of Word to be inserted
into a table. The I keep record of which documents were
printed .
 
P

Patrick

Perhaps you should try:
sqlPers = "INSERT INTO Historikk
VALUES ('" & WordDoc & "')"
I'm not sure if the "()" will prevent this from working.
If it doesn't work remove the "()" and try-it again..

This should work(not tested),
Hope this helps,

PAtrick
 
R

Ronny

Thank you, it works...

-----Original Message-----
Perhaps you should try:
sqlPers = "INSERT INTO Historikk
VALUES ('" & WordDoc & "')"
I'm not sure if the "()" will prevent this from working.
If it doesn't work remove the "()" and try-it again..

This should work(not tested),
Hope this helps,

PAtrick

.
 

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