Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inputing data into a MSAccess database (07) with MSWord (07) forms

6 views
Skip to first unread message

AlexFagg

unread,
Apr 11, 2010, 10:18:01 AM4/11/10
to
i have being trying to input data into an access (2007) database from a word
form (2007) and have looked at this link:
http://msdn.microsoft.com/en-us/library/aa155434(office.10).aspx

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

david

unread,
Apr 11, 2010, 10:18:10 PM4/11/10
to
1) You haven't put line numbers on your lines. If you put
line numbers on your lines, you can use ERL to see what
line caused the error.

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...

0 new messages