Problem with code to Import from Word

D

DanSmoach

I'm trying to get data from a Word form (using form controls/bookmarks) using
the code from Sean Kavanaghs article from Dec 2001 (which has been discussed
in previous posts), but keep getting the following error from the line from
the code below
........................
With rst
.AddNew
.........................
-2147217900: Invalid SQL statement; expected 'Delete', 'Insert',
'Procedure', 'select', or 'update'.

Any ideas or help would be very gratefully received.

Cheers

Dan


Here is the code:

Sub GetCRData()

Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim StrDocName As String
Dim blnQuitWord As Boolean

On Error GoTo ErrorHandling

StrDocName = "C:\CR\CR Test.doc"
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(StrDocName)
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and
Settings\roachd\My Documents\CR Import Test.mdb;"

rst.Open "CR Import", cnn, adOpenKeyset, adLockOptimistic

With rst
..AddNew
!ProjectName = doc.FormFields("ProjectName").Result
..Update
..Close

End With

doc.Close
If blnQuitWord Then appWord.Quit

cnn.Close

MsgBox "CR imported!"

Cleanup:

Set rst = Nothing
Set cnn = Nothing
Set doc = Nothing
Set appWord = Nothing

Exit Sub

ErrorHandling:

Select Case Err

Case -2147022986, 429
Set appWord = CreateObject("Word.Application")
blnQuitWord = True
Resume Next
Case 5941
MsgBox "The document dioes not contain form fields", vbOKOnly, _
"Fields not found"
Case Else
MsgBox Err & ": " & Err.Description

End Select

GoTo Cleanup

End Sub
 

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