• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 469
  • Last Modified:

Treeview image error 2220

I have a treeview in which I would like to display bitmap images from an ImageList but when the code runs it results in an error message "Error: 2220  ... can't open file 'C:\....\xxx.bmp'".

So far I have only tried to add the image to one treeview level.

MS Access is running on an XP Pro SP2 box connected to a SQL Server 2000 database.

Please refer to the attached code snippet and bitmap.

Thanks,
merdeka
Private Sub Form_Load()
On Error GoTo Err_Form_Load
 
Dim ImageList1 As ImageList
 
 Dim Img1 As ListImage
   Dim BitmapPath As String
    BitmapPath = "C:\Program Files\CPCTimesheet\MultiItems.bmp"
   
   Set Img1 = ImageList1.ListImages.Add(, , LoadPicture(BitmapPath))
 
'Load WBS0 treeview
 
 
 
Dim strSQLX As String '- first query
Dim strSQLY As String '- second query
Dim strSQLZ As String '- z query
Dim strSQLZ3 As String '- third query
Dim strSQLZ4 As String '- fourth query
Dim strSQLZ5 As String '- fifth query
 
 
Dim strSQL01a As String
Dim strSQL01b As String
Dim strSQL01c As String
Dim strSQL01d As String
 
Dim strSQL02a As String
Dim strSQL02b As String
Dim strSQL02c As String
 
Dim strSQL03a As String
Dim strSQL03b As String
 
Dim strSQL04a As String
 
Dim int02Loop As Integer 'increment variable for rs02
 
 
 Dim W05Node As Node
 
 Dim rs01 As Recordset
 Dim rs02 As Recordset
 Dim rs03 As Recordset
 Dim rs04 As Recordset
 Dim rs05 As Recordset
 
 Dim Db As Database
 Set Db = CurrentDb
 
 
 int02Loop = 0
 
 Me!lstSelectedWork.Requery
 
 
strSQLX = ("SELECT DISTINCT tbl_WBS01.code_L1, tbl_WBS01.desc_L1 " & _
"FROM tbl_Phase INNER JOIN (tbl_EmpResourceType INNER JOIN tbl_WBS01 ON " & _
"left(tbl_EmpResourceType.w05_projcode,7)=tbl_WBS01.code_L1) ON " & _
"left(tbl_Phase.w05_projcode,7)=tbl_WBS01.code_L1 " & _
"WHERE (((tbl_Phase.Status) <> ""C"") " & _
"And ((tbl_EmpResourceType.PersonCode) = """ & [Forms]![MyTimesheet]![txtUsername] & """)) " & _
"ORDER BY tbl_WBS01.code_L1;")
 
 
 
 Set rs01 = Db.OpenRecordset(strSQLX)
 
 
  
 With tvWBS0.Nodes
  While rs01.EOF = False
      
      
      
      .Add , , "a" & rs01!code_L1, rs01!code_L1 & " - " & rs01!Desc_L1, Image:=Img1
 
 
Set rs02 = Db.OpenRecordset _
("SELECT DISTINCT tbl_WBS02.w01code_L1, tbl_WBS02.code_L1, tbl_WBS02.desc_L1, tbl_WBS02.wbs02ID " & _
"FROM (tbl_EmpResourceType INNER JOIN (((tbl_WBS02 INNER JOIN tbl_WBS03 ON " & _
"tbl_WBS02.code_L1 = tbl_WBS03.w02code_L1) INNER JOIN tbl_WBS04 ON tbl_WBS03.code_L1 = tbl_WBS04.w03code_L1) " & _
"INNER JOIN tbl_WBS05 ON tbl_WBS04.code_L1 = tbl_WBS05.w04code_L1) ON " & _
"tbl_EmpResourceType.w05_projcode = tbl_WBS05.code_L1) INNER JOIN " & _
"(tbl_Phase INNER JOIN tbl_WBS24 ON tbl_Phase.Code_L1 = tbl_WBS24.PhaseCode) ON " & _
"tbl_EmpResourceType.ResourceType = tbl_WBS24.procurementTypeID " & _
"WHERE (((tbl_EmpResourceType.PersonCode)=""" & [Forms]![MyTimesheet]![txtUsername] & """) AND " & _
"((tbl_Phase.Status)<>""C"")) and tbl_wbs02.w01code_l1 = """ & rs01!code_L1 & """ ", dbOpenDynaset)
 
 
     
     While rs02.EOF = False
      .Add "a" & rs01!code_L1, tvwChild, _
          "b" & rs02!code_L1 & rs02!wbs02ID, rs02!code_L1 & " - " & rs02!Desc_L1 & rs02!wbs02ID '& int02Loop
      
 
 
 
strSQLZ3 = ("SELECT DISTINCT tbl_WBS03.code_L1, tbl_WBS03.WBS03ID, tbl_WBS03.desc_L1 " & _
"FROM tbl_Phase INNER JOIN (tbl_EmpResourceType INNER JOIN tbl_WBS03 ON " & _
"mid(tbl_EmpResourceType.w05_projcode,15,7)=tbl_WBS03.code_L1) ON " & _
"mid(tbl_Phase.w05_projcode,15,7)=tbl_WBS03.code_L1 " & _
"WHERE (((tbl_Phase.Status) <> ""C"") " & _
"AND tbl_WBS03.w02code_L1 = """ & rs02!code_L1 & """ " & _
"AND tbl_WBS03.w01code_L1 = """ & rs01!code_L1 & """ " & _
"And ((tbl_EmpResourceType.PersonCode) = """ & [Forms]![MyTimesheet]![txtUsername] & """)) " & _
"ORDER BY tbl_WBS03.code_L1;")
 
 
 
Set rs03 = Db.OpenRecordset(strSQLZ3)
        
        While rs03.EOF = False
      .Add "b" & rs02!code_L1 & rs02!wbs02ID, tvwChild, _
           "c" & rs03!code_L1 & rs03!wbs03ID, rs03!code_L1 & " - " & rs03!Desc_L1 & rs03!wbs03ID
           
        
        
 
strSQLZ4 = ("SELECT DISTINCT tbl_WBS04.code_L1, tbl_WBS04.WBS04ID, tbl_WBS04.desc_L1 " & _
"FROM tbl_Phase INNER JOIN (tbl_EmpResourceType INNER JOIN tbl_WBS04 ON " & _
"mid(tbl_EmpResourceType.w05_projcode,22,7)=tbl_WBS04.code_L1) ON " & _
"mid(tbl_Phase.w05_projcode,22,7)=tbl_WBS04.code_L1 " & _
"WHERE (((tbl_Phase.Status) <> ""C"") " & _
"AND tbl_WBS04.w03code_L1 = """ & rs03!code_L1 & """ " & _
"AND tbl_WBS04.w02code_L1 = """ & rs02!code_L1 & """ " & _
"AND tbl_WBS04.w01code_L1 = """ & rs01!code_L1 & """ " & _
"And ((tbl_EmpResourceType.PersonCode) = """ & [Forms]![MyTimesheet]![txtUsername] & """)) " & _
"ORDER BY tbl_WBS04.code_L1;")
 
 
        
Set rs04 = Db.OpenRecordset(strSQLZ4)
        
        
        While rs04.EOF = False
      .Add "c" & rs03!code_L1 & rs03!wbs03ID, tvwChild, _
           "d" & rs04!code_L1 & rs04!wbs04ID, rs04!code_L1 & " - " & rs04!Desc_L1
           
 
strSQLZ5 = ("SELECT DISTINCT tbl_WBS05.code_L1, Mid(tbl_WBS05.code_L1, 22, 7),tbl_WBS05.desc_L1 " & _
"FROM tbl_Phase INNER JOIN (tbl_EmpResourceType INNER JOIN tbl_WBS05 ON " & _
"tbl_EmpResourceType.w05_projcode=tbl_WBS05.code_L1) ON " & _
"tbl_Phase.w05_projcode=tbl_WBS05.code_L1 " & _
"WHERE (((tbl_Phase.Status) <> ""C"") " & _
"AND Mid(tbl_WBS05.code_L1, 22, 7) = """ & rs04!code_L1 & """ " & _
"And ((tbl_EmpResourceType.PersonCode) = """ & [Forms]![MyTimesheet]![txtUsername] & """)) " & _
"ORDER BY tbl_WBS05.code_L1;")
 
        
Set rs05 = Db.OpenRecordset(strSQLZ5)
 
 
        
   
      While rs05.EOF = False
        .Add "d" & rs04!code_L1 & rs04!wbs04ID, tvwChild, _
          "e" & rs05!code_L1, Mid(rs05!code_L1, 29, 10) & " * " & rs05!Desc_L1
        
        rs05.MoveNext
          
               Wend
              rs04.MoveNext
              rs05.Close
          Wend
          rs03.MoveNext
          rs04.Close
      Wend
      rs02.MoveNext
      rs03.Close
    Wend
    rs01.MoveNext
    rs02.Close
 
  Wend
  rs01.Close
 
 End With
 
 Me!tvWBS1.Nodes.Clear
 Me!tvWBS2.Nodes.Clear
 
 
 Set Db = Nothing
 Set rs01 = Nothing
 Set rs02 = Nothing
 Set rs03 = Nothing
 Set rs04 = Nothing
 Set rs05 = Nothing
 
Exit_Form_Load:
    Exit Sub
 
Err_Form_Load:
    MsgBox "Error: " & Err.Number & vbCrLf & Err.Description, vbExclamation, "Error"
    Resume Exit_Form_Load
 
End Sub

Open in new window

MuliItems.bmp
0
merdeka
Asked:
merdeka
1 Solution
 
merdekaAuthor Commented:
Hi ralmada,
The problem isn't that the image file doesn't exist at the location specified.  What I am trying to do is add 'icons' to the treeview and there is only two images and the location of the file (path) is known.  

The code in the link is for the case where the image file does not exist at the path specified by the user.  This is a little different than my situation.

Thanks,
merdeka
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now