Access list box merged with Word

T

T

Hi All,
I have an Access list box that has several names in it. I have a Word
document that I need to merge these names into.

How do I
get the first name
merge into document
get the second name
merge into document

This is what I have so far

Private Sub PPAuth()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim strPassword As String
Dim rsAH As DAO.Recordset
Dim dbAH As Database
Dim strAcctHName As String
Dim lngAcctHolder As Long

Set dbAH = CurrentDb()
Set rsAH = dbAH.OpenRecordset("AccountHolders", dbOpenDynaset,
dbSeeChanges)
Dim dAH1 As Long
Dim numitem As Integer, IAH As Long
numitem = Forms![main]![lstAcctHolders].ListCount
For IAH = 0 To numitem - 1
If Forms!main!lstAcctHolders.Column(26, IAH) = True Then
'Active AH
dAH1 = Forms!main!lstAcctHolders.Column(1, IAH)
End If
With rsAH

.MoveFirst
.FindFirst "[Holder ID] = " & dAH1
If Not NoMatch Then
strAcctHName = ![Name]
strtaxid = ![Tax ID]
'Call ResetCustomerDate

On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If

Set objDoc = objWord.Documents.Add(RunTemplate)
objWord.Visible = True
objDoc.Visible = True

If objWord.ActiveDocument.ProtectionType <> wdNoProtection Then
strPassword = DLookup("[Password]", "DocumentPassword",
"[Document] = '" & RunName & "'")
objWord.ActiveDocument.Unprotect strPassword
End If
With objWord
'Page Header Section
.ActiveDocument.Bookmarks("CustomerName").Select
.Selection.Text = Nz((Forms!main!lstCustomer.Column(0)))
.ActiveDocument.Bookmarks("AHName").Select
.Selection.Text = strAcctHName
'Nz((Forms!Main!lstAcctHolders.Column(0)))
.ActiveDocument.Bookmarks("AHName2").Select
.Selection.Text = strAcctHName
'Nz((Forms!Main!lstAcctHolders.Column(0)))
.ActiveDocument.Bookmarks("TaxID").Select
.Selection.Text = strtaxid

If OutFormat = "Printer" Then
Dim STDPrinter As String
Dim lngDfltPBin As Long
Dim lngNewPBin As Long

lngDfltPBin = Printer.PaperBin
'Printer.PaperBin = 3 'letterhead in TM printer
Printer.PaperBin = acPRBNMiddle 'references Bin 3 which
is Letterhead


STDPrinter = .ActivePrinter
.ActivePrinter = OutFile
.PrintOut
.ActivePrinter = STDPrinter
Printer.PaperBin = lngDfltPBin
objDoc.Close wdDoNotSaveChanges
Set objDoc = Nothing
Set objWord = Nothing


End If
End With
End If
End With

Next IAH
rsAH.Close

End Sub

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top