Results 1 to 5 of 5

Thread: [RESOLVED] Need help with listview

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Resolved [RESOLVED] Need help with listview

    Hello everyone
    This is my table
    Name:  2016-05-28 18-47-25.png
Views: 125
Size:  8.6 KB

    Name:  2.jpg
Views: 110
Size:  12.6 KB

    To feed my listview with this data in the table:

    Code:
    Code:
     RS.Open "select * from Table1 where num like '" & Text1.Text & "'", DB, adOpenStatic, adLockOptimistic
    Dim Lst As ListItem
       Do While Not RS.EOF
                With lvw.ListItems.Add(, , RS!datebirth & "")
                   .SubItems(1) = RS!Val_y
                   .SubItems(2) = RS!Tal_m
                   .SubItems(3) = RS!Moc_d
                   .SubItems(4) = RS!Type_s       
            End With          
       RS.MoveNext
    Loop
    End If
    What I'm looking for is to modify the code in such a way not to display the records where the fields Val_y, , Tal_m, Moc_d = 0
    I mean I want to display only the records whose fields Val_y, , Tal_m, Moc_d do not contain 0.
    If all the three fields contain 0 , they should not be retrieved in the listview.
    Is that possible?
    Thank you in advance
    Last edited by samer22; May 28th, 2016 at 02:52 PM.

  2. #2
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    Re: Need help with listview

    change your query.

    Code:
    "select * from Table1 where num like '" & Text1.Text & "%'"
    to
    Code:
    "select * from Table1 where num like '" & Text1.Text & "%' AND ([Val_y] <> 0) AND ([tal_m] <> 0) AND (moc_d <> 0)"
    notice you're declaring Lst as ListItembut not using it, might as well remove that line.
    also, make sure you add null-string to the value retrieved on your sub-items, or it's gonna throw an error when a null value is retrieved from that table - exactly like you did with datebirth.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: Need help with listview

    Thank you very much stum
    But I'm sorry to tell you that I still have a problem
    What I need is that
    If all the three fields contain 0 , they should not be retrieved in the listview.
    however when I used this code even if one field contain 0 , the whole record is not retrieved.
    Example
    Val_y Tal_m moc_d

    10 0 5
    Here the code doesn't retrieve this record
    What I need is that the record is ignored if
    Val_y Tal_m moc_d

    0 0 0
    thank you

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,219

    Re: Need help with listview

    Change the AND to OR in each place.

    As is it will return only records where none of those fields are 0
    If you use or then it will return records where any one of the three are not 0

    I think that is what you were wanting?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    700

    Re: Need help with listview

    DataMiser
    you have always been my saver
    thanks a lot

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