Access.2007.VBA.Bibl..

(John Hannent) #1
Determine whether the template is for labels or list, and move to the first data cell in table if
needed:

If Nz(InStr(strWordTemplate, “List”)) > 0 Then
appWord.Selection.GoTo what:=wdGoToTable, _
which:=wdGoToFirst, _
Count:=1
appWord.Selection.MoveDown unit:=wdLine, _
Count:=1
End If

Set the intModvalue depending on the number of cells per row:

strDocType = _
doc.BuiltInDocumentProperties(wdPropertyTitle)
Select Case strDocType

Case “Avery 5160 Labels”
intMod = 3

Case “Avery 5161 Labels”
intMod = 2

Case “Avery 5162 Labels”
intMod = 2

End Select

Check that at least one contact has been selected:

Set lst = Me![lstSelectContacts]

If lst.ItemsSelected.Count = 0 Then
MsgBox “Please select at least one contact”
lst.SetFocus
GoTo ErrorHandlerExit
End If

intColumns = lst.ColumnCount
intRows = lst.ItemsSelected.Count

For Each varItem In lst.ItemsSelected

Check for required information:

strTest = Nz(lst.Column(1, varItem))
Debug.Print “Contact name: “ & strTest
If strTest = “” Then
Debug.Print _
“Skipping this record -- no contact name!”
GoTo NextContact

Part II Writing VBA Code to Exchange Data between Office Components

Free download pdf