|
-
Dec 2nd, 2002, 07:21 PM
#1
Thread Starter
Member
Can't figure it out
Hello to all,
Here is what I am looking for.
Step A
========
I checked off all the customers in the list. Some customers may have an address while others don't. When I click the Print button, **only** customers with valid addresses will be printed out. That's when I called --->> Call GetCustomerBookMark(k)
Step B
========
On the other hand, If I clicked on the list and selected customers without no addresses, then no letters will be printed out for those customers. That's when I **DON'T called --->> Call GetCustomerBookMark(k). I just exit out. These are validation I am doing on the Print Button. See sample below.
My code works for Step A. How do you changed it to work for
Both Step A and Step B.
Data in the ListView
Names Address City State Zip
===================================
[X] Don Joe **has no address **
[X] Ben Joe **has no address**
[X] Sally 1 Pine Street
[X] Jorge 3030 Mapel Street
With the code below, letters will be printed for
Sally and Jorge only because they have an address.
See code below which works for Step A.
Private sub PrintCustomer()
call VerifyAddress
end Sub
Private Sub VerifyAddress()
Dim k As Integer
Dim intpos As Integer
Dim CustID As Long
Dim strCustNames As String
Dim strMsg As String
If Me.LvwCustomer.ListItems.Count > 0 Then
For k = 1 To Me.LvwCustomer.ListItems.Count
If Me.LvwCustomer.ListItems.Item(k).Checked Then
intpos = InStr(1, Me.LvwCustomer.ListItems.Item(k).Key, "C", vbTextCompare)
'use for other uses.
CustID = CLng(Mid(Me.LvwCustomer.ListItems.Item(k).Key, 2, Len(Me.LvwCustomer.ListItems.Item(k).Key) - intpos))
If Len(Trim(Me.LvwCustomer.ListItems.Item(k).SubItems(5))) = 0 And _ 'address
Len(Trim(Me.LvwCustomer.ListItems.Item(k).SubItems(6))) = 0 And _ 'apt
Len(Trim(Me.LvwCustomer.ListItems.Item(k).SubItems(7))) = 0 And _ 'City
Len(Trim(Me.LvwCustomer.ListItems.Item(k).SubItems(8))) = 0 And _ 'state
Len(Trim(Me.LvwCustomer.ListItems.Item(k).SubItems(9))) = 0 And _ 'zip
Len(Trim(Me.LvwCustomer.ListItems.Item(k).SubItems(10))) = 0 Then 'country
'uncheck the Customer that has no address
Me.LvwCustomer.ListItems.Item(k).Checked = False
strCustNames = strWitNames & LvwCustomer.ListItems.Item(k) & vbTab & _
LvwCustomer.ListItems.Item(k).SubItems(1) & " " & LvwCustomer.ListItems.Item(k).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
End If
Call GetCustomerBookMark(k)
End If
Next k
MsgBox strMsg, vbInformation + vbOKOnly, "No Letters Printed"
End If
End Sub
I have a hard time getting it to work.
thanks a bunch.
-
Dec 3rd, 2002, 12:06 AM
#2
Fanatic Member
I hope I understood you right. You just need a conditional statement. If address is good print, else don't print. Isn't that what you need?
I cleaned it up a bit. Also if you use the tags (without the spaces before or after the brackets!), your code will appear much neater here.
I hope this helps you . . .
VB Code:
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
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Dec 3rd, 2002, 06:30 PM
#3
Thread Starter
Member
Hi,
You did it. You are great.
BTW: you left out the END WITH. That I fixed.
Also the strWitNames need to change to strCustNames
thanks a bunch
-
Dec 3rd, 2002, 06:45 PM
#4
Fanatic Member
Hey, glad I could help! What the heck happened to my End With? Must be too much coffee!
Also, whenever your problem is resovled here, edit the subject line of your original message to include *Resolved*
Take care.
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|