Results 1 to 4 of 4

Thread: Can't figure it out

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    62

    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.

  2. #2
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    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
    [ vbcode ] [ /vbcode ]
    tags (without the spaces before or after the brackets!), your code will appear much neater here.

    I hope this helps you . . .

    VB Code:
    1. Private Sub PrintCustomer()
    2.     Call VerifyAddress
    3. End Sub
    4.  
    5. Private Sub VerifyAddress()
    6.  
    7. Dim k As Integer
    8. Dim intpos As Integer
    9. Dim intListCount As Integer
    10. Dim intPrintCount As Integer
    11. Dim CustID As Long
    12. Dim strCustNames As String
    13. Dim strMsg As String
    14.  
    15.     intPrintCount = 0
    16.     intListCount = lvwCustomer.ListItems.Count 'this way we only need to resolve this once!
    17.     If intListCount > 0 Then
    18.         For k = 1 To intListCount
    19.             If lvwCustomer.ListItems.Item(k).Checked Then
    20.                 intpos = InStr(1, lvwCustomer.ListItems.Item(k).Key, "C", vbTextCompare)
    21.                 'use for other uses.
    22.                 CustID = CLng(Mid(lvwCustomer.ListItems.Item(k).Key, 2, Len(lvwCustomer.ListItems.Item(k).Key) - intpos))
    23.                 With lvwCustomer.ListItems.Item(k) 'only need to reference the object once this way!
    24.                     If Len(Trim(.SubItems(5))) = 0 And _
    25.                         Len(Trim(.SubItems(6))) = 0 And _
    26.                         Len(Trim(.SubItems(7))) = 0 And _
    27.                         Len(Trim(.SubItems(8))) = 0 And _
    28.                         Len(Trim(.SubItems(9))) = 0 And _
    29.                         Len(Trim(.SubItems(10))) = 0 Then
    30.                    'uncheck the Customer that has no address
    31.                         .Checked = False
    32.                         strCustNames = strWitNames & .Text & vbTab & .SubItems(1) & " " & .SubItems(2)
    33.                         If Len(Trim(strCustNames)) > 0 Then strWitNames = strCustNames & vbCrLf
    34.                             strMsg = ("No letters will be printed for the following Customer") & vbCrLf & "" _
    35.                             & "____________________________________________ " & vbCrLf & strCustNames & vbCrLf
    36.                     Else
    37.                         'address is good - call print routine
    38.                         intPrintCount = intPrintCount + 1
    39.                         Call GetCustomerBookMark(k)
    40.                     End If
    41.             End If
    42.         Next k
    43.         'inform the user what we did
    44.         If intPrintCount = 0 Then
    45.             MsgBox strMsg, vbInformation + vbOKOnly, "No Letters Printed"
    46.         Else
    47.             MsgBox intPrintCount & " letters printed"
    48.         End If
    49.     Else
    50.         'no boxes were checked- nothing to print!
    51.         MsgBox "Nothing selected - Nothing printed!"
    52.     End If
    53.  
    54. 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!

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2001
    Posts
    62
    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

  4. #4
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    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
  •  



Click Here to Expand Forum to Full Width