Hello,
I am working on trying to get Access data from a form into Word when the person clicks a button. I got most of the kinks worked out by perusing the forums here but this one has me scratching my head. I keep getting a runtime error 424 access object required.
Here is my code and I highlighted in bold the relevant section that VBA highlights:
I am working on trying to get Access data from a form into Word when the person clicks a button. I got most of the kinks worked out by perusing the forums here but this one has me scratching my head. I keep getting a runtime error 424 access object required.
Here is my code and I highlighted in bold the relevant section that VBA highlights:
Code:
Private Sub cmd_Word_Click()
'Declare Variables
Dim sAccessAddress As String
Dim sAccessSalutation As String
'Build sAccessAddress
sAccessAddress = FirstName & " " & LastName & vbCrLf & Address & vbCrLf & StateOrProvince & " " & Zipcode
'Build sAccessSalutation
sAccessSalutation = FirstName & " " & LastName
'Declare and set Word object variables
Dim Wrd As New Word.Application
[B][COLOR=Black]Set Wrd = CreateObject(“Word.Application”)[/COLOR][/B] <- here is where the debug highlights in yellow
'Specify Path to Template
Dim sMergeDoc As String
sMergeDoc = Application.CurrentProject.Path & "C:\Users\dwilson\Desktop\Ron's Files\CHC Admin Program 2003\WordMergeDocument.dotx”"
'Open Word using template and make Word visible
Wrd.Documents.Add sMergeDoc
Wrd.Visible = True
'Replace Bookmarks with Values
With Wrd.ActiveDocument.Bookmarks
.Item(“CurrentDate”).Range.Text = Date
.Item(“AccessAddress”).Range.Text = sAccessAddress
.Item(“AccessSalutation”).Range.Text = sAccessSalutation
End With
'Open in PrintPreview mode, let user print
Wrd.ActiveDocument.PrintPreview
'Clean Up code
Set Wrd = Nothing
End Sub