Please can someone help
i have used this coding:
Sub GetWordData()
Dim appWord As Word.Application
Dim doc As Word.Document
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strDocName As String
Dim blnQuitWord As Boolean
On Error GoTo ErrorHandling
strDocName = "C:\Users\Alex\Documents\My Work\other\test2\Contracts\" &
InputBox("Enter the name of the Word contract " & "you want to import:",
"Import Contract")
Set appWord = GetObject(, "Word.Application")
Set doc = appWord.Documents.Open(strDocName)
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\Users\Alex\Documents\My Work\other\test2\" & "Healthcare
Contracts.accdb;"
rst.Open "tblContracts", cnn, adOpenKeyset, adLockOptimistic
With rst
.AddNew
!FirstName = doc.FormFields("fldFirstName").Result
!LastName = doc.FormFields("fldLastName").Result
!Company = doc.FormFields("fldCompany").Result
!Address = doc.FormFields("fldAddress").Result
!City = doc.FormFields("fldCity").Result
!State = doc.FormFields("fldState").Result
!ZIP = doc.FormFields("fldZIP1").Result & "-" &
doc.FormFields("fldZIP2").Result
!Phone = doc.FormFields("fldPhone").Result
!SocialSecurity = doc.FormFields("fldSocialSecurity").Result
!Gender = doc.FormFields("fldGender").Result
!BirthDate = doc.FormFields("fldBirthDate").Result
!AdditionalCoverage = doc.FormFields("fldAdditional").Result
.Update
.Close
End With
doc.Close
If blnQuitWord Then appWord.Quit
cnn.Close
MsgBox "Contract 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 5121, 5174
MsgBox "You must select a valid Word document. " & "No data imported.",
vbOKOnly, "Document Not Found"
Case 5941
MsgBox "The document you selected does not " & "contain the required
form fields. " & "No data imported.", vbOKOnly, "Fields Not Found"
Case Else
MsgBox Err & ": " & Err.Description
End Select
GoTo Cleanup
End Sub
but i keep getting this message come up :
Microsoft Office Access
91: Object variable or With block variable not set
PLEASE HELP !! :)
thanks
Alexander Fagg
ps. wasnt sure which forum to post this in, sorry if not best one please
suggest better one if there is one :D
2) If you don't have line numbers on your lines, you can
set "Break On All Errors" in the options for your project.
3) The first object that I can see that is not set is "cnn"
4) Anyway, you can't use the Jet 4 provider with an ACCDB.
You need to use "Provider=Microsoft.ACE.OLEDB.12.0;"
(david)
"AlexFagg" <Alex...@discussions.microsoft.com> wrote in message
news:6A42635F-E54B-4D23...@microsoft.com...