INSERT INTO in VBA using a variable

  • Thread starter Thread starter Ronny
  • Start date Start date
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 .
 
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
 
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

.
 
Back
Top