Hi all,
I have a dilemma. I have an Access form that I need to auto fill multiple forms. These forms may not have all the bookmarks so I want to use a loop but I don't know which one to use. I know about IF/THEN, IF/ELSE, FOR/NEXT, CASE but I am stuck on which on. I need the loop to go to each one and see if it's there and if not then keep going and filling in the other bookmarks if they exist.
I hope that was not to muddled. Here is my code:
In red is where I want to put a loop.
I have a dilemma. I have an Access form that I need to auto fill multiple forms. These forms may not have all the bookmarks so I want to use a loop but I don't know which one to use. I know about IF/THEN, IF/ELSE, FOR/NEXT, CASE but I am stuck on which on. I need the loop to go to each one and see if it's there and if not then keep going and filling in the other bookmarks if they exist.
I hope that was not to muddled. Here is my code:
Code:
Private Sub cmd_Word_Click()
'Declare Variables
Dim sAccessAddress As String
Dim Salutation As String
'Build sAccessAddress
sAccessAddress = FirstName & " " & LastName & vbCrLf & Address & vbCrLf & StateOrProvince & " " & Zipcode
'Build sAccessSalutation
Salutation = FirstName & " " & LastName
'Declare and set Word object variables
Dim Wrd As Word.Application
Set Wrd = CreateObject("Word.Application")
'Specify Path to Template
Dim sMergeDoc As String
sMergeDoc = Application.CurrentProject.Path & "\WordMergeDocument.dotx"
'Open Word using template and make Word visible
Wrd.Documents.Add sMergeDoc
Wrd.Visible = True
'Replace Bookmarks with Values
[COLOR=Red]With Wrd.ActiveDocument.Bookmarks
.Item("CurrentDate").Range.Text = Date
.Item("AccessAddress").Range.Text = sAccessAddress
.Item("Salutation").Range.Text = Salutation
End With[/COLOR]
'Open in PrintPreview mode, let user print
Wrd.ActiveDocument.PrintPreview
'Clean Up code
Set Wrd = Nothing
End Sub
In red is where I want to put a loop.