I have code on the on click command to trigger a custom form template generated by Word to be populated by certain fields in my database. When I click the button, I get a run time error 4248 saying "This command is not available because no document is open" I will post my code below, can someone have a look and help me figure this one out?
Code:
Private Sub Mergebttn_Click()
'Declare Variables for storing strings
Dim AddyLineVar As String, SalutationVar As String
If IsNull([LastName]) Then
AddyLineVar = [VendorName]
Else
AddyLineVar = [FirstName] & " " & [LastName] & " " & [Suffix] & " " & [Title]
SalutationVar = [FirstName] & " " & [LastName]
End If
AddyLineVar = AddyLineVar & vbCrLf & [Address1]
If Not IsNull([Address2]) Then
AddyLineVar = AssyLineVar & vbCrLf & [Address2]
End If
AddyLineVar = AddyLineVar & vbCrLf & [City] & ", "
AddyLineVar = AddyLineVar & [State] & " " & [Zip]
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
Dim MergeDoc As String
MergeDoc = Application.CurrentProject.Path
MergeDoc = MergeDoc & "\EchoDomestic.dotx"
Wrd.Visible = True
With Wrd.ActiveDocument.Bookmarks
.Item("VendorName").Range.Text = AddyLineVar
.Item("TodaysDate").Range.Text = Date
.Item("ContactPerson").Range.Text = SalutationVar
End With
Wrd.ActiveDocument.PrintOut
Wrd.ActiveDocument.Close wdDoNotSaveChanges
End Sub
When I debug, the line that highlights is this:
Code:
With Wrd.ActiveDocument.Bookmarks
Hopefully someone can help me through, if you need more information let me know. Thank you all so much.
Ken