Results 1 to 24 of 24

Thread: Problem with ListView

  1. #1

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396

    Problem with ListView

    Hello Everyone
    I'm trying to use ListView to get contents of an Access Table into it...And I use the following code to do so...but while executing the statements I get an error- Invalid property Value
    Please help!!!!

    Dim Db As Database
    Dim Rs As Recordset
    Dim SQL As String
    Dim MyItem As ListItem
    Private Sub Form_Load()
    Set Db = OpenDatabase("d:\check\taws\data.mdb")
    SQL = "SELECT * FROM Audit "
    Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
    Do While Not Rs.EOF
    Set MyItem = ListView1.ListItems.Add(, , Rs(0))
    MyItem.SubItems(1) = Rs(0)
    MyItem.SubItems(2) = Rs(1)
    'continue as above until all fields are accounted for
    Rs.MoveNext
    Loop
    Rs.Close
    End Sub

  2. #2
    PWNettle
    Guest
    How many columns does your listview have?

    This code:
    Code:
    Set MyItem = ListView1.ListItems.Add(, , Rs(0)) 
    MyItem.SubItems(1) = Rs(0) 
    MyItem.SubItems(2) = Rs(1)
    Is kind of interesting since it has you adding Rs(0) for the text of the listview (column 1) then putting it in column 2 as well with MyItem.SubItems(1) = Rs(0).

    Are you intending to put the same database value in both columns 1 and 2?

    Normally when I add an item to a listview I do so like this:
    Code:
    Set MyItem = ListView1.ListItems.Add
    With MyItem
      .Text = Rs(0)  '  Column 1 value.
      .SubItems(1) = Rs(0)   '  Column 2 value.
      .SubItems(2) = Rs(1)   '  Column 3 value.
    End With
    ...which is basically the same thing you had, just a little easier to follow for me.

    Anyways...I don't know if this helps...to really help it'd be good to know exactly where your code breaks when you get the error.

    Cheers,
    Paul

  3. #3

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Yo!
    I tried your code but it gave me the same problem I have pasted the line where it breaks and gives me an error...

    MyItem.SubItems(1) = Rs(0)

    When I put my curson for SubItems(1), it reads: Invalid property value....
    Any ideaS?

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Have you add at least 2 subitems? I don't think so.... you have to add the subitems (with ".Add") to the item.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Sth like this.... but I didn't try it:

    VB Code:
    1. Dim Db As Database
    2. Dim Rs As Recordset
    3. Dim SQL As String
    4. Dim MyItem As ListItem
    5.  
    6. Private Sub Form_Load()
    7.      Set Db = OpenDatabase("d:\check\taws\data.mdb")
    8.      SQL = "SELECT * FROM Audit "
    9.      Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
    10.      Do While Not Rs.EOF
    11.           Set MyItem = ListView1.ListItems.Add(, , Rs(0))
    12.           MyItem.SubItems.add , "FirstColumn", Rs.Fields(0)
    13.           MyItem.SubItems.add , "SecondColumn", Rs.Fields(1)
    14.           'continue as above until all fields are accounted for
    15.           Rs.MoveNext
    16.      Loop
    17.      Rs.Close
    18. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    mxnmx: Why did you post the same question twice under a different title?

  7. #7

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Around two hours ago, I think there was a problem with this site....It was giving me an error that thread not posted...while it was posted....

  8. #8

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    I tried this code, Mc Brain...but got an error.
    MyItem.SubItems.Add , "FirstColumn", Rs.Fields(0)

    It gave an error while highlighting the word Add: Argument not optional

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Is now...
    VB Code:
    1. Set MyItem = ListView1.ListItems.Add(, , Rs0))  'rs 0
    2. MyItem.SubItems(1) = Rs(0) ' rs 0
    3. MyItem.SubItems(2) = Rs(1)
    4. 'should be
    5. Set MyItem = ListView1.ListItems.Add(, , Rs(0)) rs 0
    6. MyItem.SubItems(1) = Rs(0) rs 1
    7. MyItem.SubItems(2) = Rs(1) rs 2
    8. 'etc

  10. #10
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Sorry... My mistake. It's "ListSubItem" (instead of SubItem)
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Hack, it still gives the same error with the code that you made changes to...Mc Brain code works with ListSubItems but it doesn't display anything...at all in the List view...

  12. #12
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    You have to set the View property to Report.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  13. #13

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    With the following code, I don't get any error executing it, but it does not display anything in the ListView....

    Dim Db As Database
    Dim Rs As Recordset
    Dim SQL As String
    Dim MyItem As ListItem

    Private Sub Form_Load()
    Me.WindowState = vbMaximized

    Set Db = OpenDatabase("c:\test.mdb")
    SQL = "SELECT * FROM Details "
    Set Rs = Db.OpenRecordset(SQL, dbOpenDynaset)
    Do While Not Rs.EOF
    Set MyItem = ListView1.ListItems.Add(, , Rs(0))
    MyItem.ListSubItems.Add , "FirstColumn", Rs.Fields(0)
    MyItem.ListSubItems.Add , "SecondColumn", Rs.Fields(1)
    'continue as above until all fields are accounted for
    Rs.MoveNext
    Loop
    Rs.Close


    End Sub

  14. #14
    PWNettle
    Guest
    You would need the ListView setup in Report mode (as stated above) and need 3 columns.
    Code:
    With ListView1
      .View = lvwReport
      .FullRowSelect = True
      .ColumnHeaders.Add , , "Column 1", 1440
      .ColumnHeaders.Add , , "Column 2", 1440
      .ColumnHeaders.Add , , "Column 3", 1440
    End With
    All of which can be done by right-clicking on the listview and selecting properties.

    Paul

  15. #15
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Excellent point. I forgot about that.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  16. #16

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Ok, it works...Thanks people...Now is there a way to make it look a bit better or atleast...This is the first time I have used a ListView....

  17. #17
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    a bit better?
    What do you mean?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  18. #18

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    You know with some lines separating each column and rows...is it possible???

  19. #19
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    mmm... I don't think so.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  20. #20
    PWNettle
    Guest
    Right-click on your listview control and select 'properties' - there are lots of things you can do to its appearance. You can use the properties through code too but it's usually easier to experiment using the "right-click" properties.

    Paul

  21. #21

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Thanks everyone!!!! We have finally made it work and change its appearance...;-)

  22. #22
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    So is it doing what you need/want it to do?

  23. #23

    Thread Starter
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Yea Hack, its working all thanks to you....and others who helped...I just need to create a query now that can search for records in three tables at the same time....I have posted a thread but haven't got any answer yet...could you help????

  24. #24
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by mxnmx
    I just need to create a query now that can search for records in three tables at the same time
    That sounds like a pretty straight forward SQL statement with a couple of JOINs. Should be no problem. I haven't seen the new thread that you created specifically for this, but I will take a look.

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