Private Sub PrintCustomer()
Call VerifyAddress
End Sub
Private Sub VerifyAddress()
Dim k As Integer
Dim intpos As Integer
Dim intListCount As Integer
Dim intPrintCount As Integer
Dim CustID As Long
Dim strCustNames As String
Dim strMsg As String
intPrintCount = 0
intListCount = lvwCustomer.ListItems.Count 'this way we only need to resolve this once!
If intListCount > 0 Then
For k = 1 To intListCount
If lvwCustomer.ListItems.Item(k).Checked Then
intpos = InStr(1, lvwCustomer.ListItems.Item(k).Key, "C", vbTextCompare)
'use for other uses.
CustID = CLng(Mid(lvwCustomer.ListItems.Item(k).Key, 2, Len(lvwCustomer.ListItems.Item(k).Key) - intpos))
With lvwCustomer.ListItems.Item(k) 'only need to reference the object once this way!
If Len(Trim(.SubItems(5))) = 0 And _
Len(Trim(.SubItems(6))) = 0 And _
Len(Trim(.SubItems(7))) = 0 And _
Len(Trim(.SubItems(8))) = 0 And _
Len(Trim(.SubItems(9))) = 0 And _
Len(Trim(.SubItems(10))) = 0 Then
'uncheck the Customer that has no address
.Checked = False
strCustNames = strWitNames & .Text & vbTab & .SubItems(1) & " " & .SubItems(2)
If Len(Trim(strCustNames)) > 0 Then strWitNames = strCustNames & vbCrLf
strMsg = ("No letters will be printed for the following Customer") & vbCrLf & "" _
& "____________________________________________ " & vbCrLf & strCustNames & vbCrLf
Else
'address is good - call print routine
intPrintCount = intPrintCount + 1
Call GetCustomerBookMark(k)
End If
End If
Next k
'inform the user what we did
If intPrintCount = 0 Then
MsgBox strMsg, vbInformation + vbOKOnly, "No Letters Printed"
Else
MsgBox intPrintCount & " letters printed"
End If
Else
'no boxes were checked- nothing to print!
MsgBox "Nothing selected - Nothing printed!"
End If
End Sub