Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with listview images

Status
Not open for further replies.

dbadamion

IS-IT--Management
Aug 2, 2007
11
US
I get Run-time error '35602'. Can someone help I want to fill my listview with images but only one image then error on the second loop


Dim itmX As ListItem
Dim nlst As Long


Public Sub display()
Dim itmX As ListItem


Dim rs As DAO.Recordset
Dim db As DAO.database

Dim lstItem As ListItem
Dim strSQL As String

Set db = CurrentDb()
strSQL = "SELECT distinct employee FROM menu"
Set rs = db.OpenRecordset(strSQL)

rs.MoveFirst
nlst = 1
Do Until rs.EOF

Call ListView1.ListItems.Add(nlst, "open", Nz(rs!employee, "NA"), "open", "open")


nlst = nlst + 1
rs.MoveNext

Loop
'close recordset
rs.Close

End Sub
 
The error message is quite clear:

lstvw.ListItems.Add("index","Key",Text","Icon","SmallIcon")

But you are

(nlst, "open", Nz(rs!employee, "NA"), "open", "open")

You are giving each items a Key of "open". You need to give each a unique Key. Normally a primary key to the record where it came from so that you tie the record to the listview. You increment an index but not the key which has to be unique.
 
Thank You.
I see what I did now . How can I add a drill down from what I have here.




Public Sub display()

Dim rs As DAO.Recordset
Dim db As DAO.database

Dim lstItem As ListItem
Dim strSQL As String

Set db = CurrentDb()
strSQL = "SELECT distinct employee FROM menu"
Set rs = db.OpenRecordset(strSQL)

rs.MoveFirst

Do Until rs.EOF


Call ListView1.ListItems.Add(, , Nz(rs!employee, "NA"), "open", "open")
'Call To Create sublist------
SubMenu(rs!employee)

'End--------

rs.MoveNext

Loop
'close recordset
rs.Close

End Sub

Public sub SubMenu( sEmployee as string)

Dim rsSub As DAO.Recordset
Dim dbSub As DAO.database


Dim strSQL As String

Set dbSub = CurrentDb()
strSQL = "SELECT distinct Title FROM menu where employee ='" & sEmployee
Set rsSub = dbSub.OpenRecordset(strSQL)

rsSub.MoveFirst

Call ListView1.ListItems.Add(, , Nz(rsSub!Title, "NA"), "open", "open")
End Sub
 
They did not have anything on drill down list. I am looking for some thing simialr to what I have below.

- Employee
|___Plumber
 
Untested but my guess is

In your main

Code:
dim itm as listitem

'replace 
'Call ListView1.ListItems.Add(, , Nz(rs!employee, "NA"), '"open", "open")
'with

     itm = ListView1.ListItems.Add(, , Nz(rs!employee, "NA"), "open", "open")
call subMenu(rs!employee,itm)

in your submenu
Code:
Public sub SubMenu( sEmployee as string, itm as listItem)

    Dim rsSub As DAO.Recordset
    Dim dbSub  As DAO.database
    Dim strSQL As String
    Set dbSub = CurrentDb()
    strSQL = "SELECT distinct Title FROM menu where employee ='" & sEmployee
    Set rsSub = dbSub.OpenRecordset(strSQL)

 rsSub.MoveFirst
 itm.subitems.Add(Nz(rsSub!Title, "NA"))
End Sub

I think the subitems add method only has one argument and that is the text to display.
 
return a listitem and then add subitems

Untested but my guess is

In your main

Code:
dim itm as listitem

'replace 
'Call ListView1.ListItems.Add(, , Nz(rs!employee, "NA"), '"open", "open")
'with

     itm = ListView1.ListItems.Add(, , Nz(rs!employee, "NA"), "open", "open")
call subMenu(rs!employee,itm)

in your submenu
Code:
Public sub SubMenu( sEmployee as string, itm as listItem)

    Dim rsSub As DAO.Recordset
    Dim dbSub  As DAO.database
    Dim strSQL As String
    Set dbSub = CurrentDb()
    strSQL = "SELECT distinct Title FROM menu where employee ='" & sEmployee
    Set rsSub = dbSub.OpenRecordset(strSQL)

 rsSub.MoveFirst
 itm.subitems.Add(Nz(rsSub!Title, "NA"))
End Sub

I think the subitems add method only has one argument and that is the text to display.
 
Where does it break?
What does your code look like?

I freehanded that code off of the top of my head so as I said it is untested, but the concept should be correct.

One mistake
employee ='" & sEmployee & "'
 
I got it to work but I do not want sub-item or additional column I want a drill menu. Where if a user clicks on the plus sign the other layer of information will be seen
 
I do not work with list views that much, is there such a feature? I do a lot with Tree views and that is doable in a tree view.
 
MS Listview has ability to group in .net scenario not in vba or vb6.
You better go for treeview as MajP suggested. Or use some third party component.
has some samples.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top