Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    59

    Unanswered: Populating ListView

    Hi All-

    I'm still too new at straight VB I suppose. I'm used to working with VBA where everything is self contained... anywho...

    I've gotten a ListView to work, thanks to some wonderful other posters, but I'm having problems on this one.

    I have the view set to "3 - Report" and I can see the column headers, but no data ever populates the ListView. I do not get any debug errors, just nothing in the listview window.

    The listview is named ListView1. I'm searching a table (tblCsrInfo), and I'm trying to pull the users (header for listview is also), Last Name | First Name | Phone Number | City.

    Here's my code, can anyone help me figure out what I'm doing wrong? Perhaps I should do this differently?

    On Form_Load
    dim stTableName as String
    stTableName = "tblCsrInfo"
    set rs = db.openrecordset(stTableName)
    rs.MoveFirst '<<-Note, ultimately, I only want it to return values where the last name = the last name typed into a text box... but maybe that should be dealt with later)
    Call SearchLast ('cause i want it to search for only the last names in the table that match what the user typed into the textbox, but for now, i've commented out those lines)
    End Sub

    Private Sub SearchLast()
    dim items as ListItems
    do until rs.EOF = TRUE
    set items = ListView1.ListItems.Add(, , rs!LastName)
    items.SubItems(1) = rs!FirstName
    items.SubItems(2) = rs!Phone1
    items.SubItems(3) = rs!City
    rs.MoveNext
    Loop
    End Sub

    any ideas for this newbie? Thanks!
    -Matt H-
    www.comperfection.com

  2. #2
    Join Date
    Jul 2004
    Posts
    69
    hi mateo! i dont think there's a problem with your code not unless your recordset is not empty. for my convenience, i use the while control statement rather than do-until...

    Private Sub SearchLast()
    dim items as ListItems

    With rs
    .MoveFirst
    While Not .EOF
    Set items = ListView1.ListItems.Add(, , !LastName)
    items.SubItems(1) = !FirstName
    items.SubItems(2) = !Phone1
    items.SubItems(3) = !City
    .MoveNext
    Wend
    End With
    End Sub

  3. #3
    Join Date
    Nov 2004
    Posts
    108
    why is this
    Code:
    Call SearchLast
    in the formLoad event?
    to err is human ; to really mess things up requires a computer

  4. #4
    Join Date
    Feb 2004
    Posts
    59
    SearchLast is the name of the routine that pulls the recordset information from the database, to put into the ListView.

    So, on page load, it loads that data. I like to code it that way, because then, i can always go back and call that routine again and again, whereas if i set it to update IN page load, i'd have to reload the whole page everytime...

    make sense? better ways?
    -Matt H-
    www.comperfection.com

  5. #5
    Join Date
    Nov 2004
    Posts
    108
    well I just thought that having that call in a command button would be more efficient. you just need to hide/show the form and clear/load data while the form remains in memory unless the form is rarely used
    to err is human ; to really mess things up requires a computer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •