I have a module that allows me to delete files from the Temporary Internet Cache. When I execute this command, it deletes all the files, but it never displays the message box and the program just freezes. Also, if I were to have a progress bar called "ProgressBar1" that would show the progress of the deletion, how would I script it?

MODULE:
VB Code:
  1. Option Explicit On
  2.  
  3. Module Module1
  4.  
  5.     Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _
  6.         ByVal dwFlags As Long, _
  7.         ByVal dwFilter As Long, _
  8.         ByRef lpSearchCondition As Long, _
  9.         ByVal dwSearchCondition As Long, _
  10.         ByRef lpGroupId As Date, _
  11.         ByRef lpReserved As Long) As Long
  12.  
  13.     Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" ( _
  14.         ByVal hFind As Long, _
  15.         ByRef lpGroupId As Date, _
  16.         ByRef lpReserved As Long) As Long
  17.  
  18.     Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _
  19.         ByVal sGroupID As Date, _
  20.         ByVal dwFlags As Long, _
  21.         ByRef lpReserved As Long) As Long
  22.  
  23.     Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll" Alias "FindFirstUrlCacheEntryA" ( _
  24.         ByVal lpszUrlSearchPattern As String, _
  25.         ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
  26.         ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long
  27.  
  28.     Private Structure INTERNET_CACHE_ENTRY_INFO
  29.         Dim dwStructSize As Long
  30.         Dim szRestOfData As Long
  31.     End Structure
  32.  
  33.     Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" ( _
  34.         ByVal lpszUrlName As Long) As Long
  35.  
  36.     Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll" Alias "FindNextUrlCacheEntryA" ( _
  37.         ByVal hEnumHandle As Long, _
  38.         ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
  39.         ByRef lpdwNextCacheEntryInfoBufferSize As Long) As Long
  40.  
  41.     Private Const CACHGROUP_SEARCH_ALL = &H0
  42.     Private Const ERROR_NO_MORE_FILES = 18
  43.     Private Const ERROR_NO_MORE_ITEMS = 259
  44.     Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE = &H2
  45.     Private Const BUFFERSIZE = 2048
  46.  
  47.     Public Sub Command1_Click()
  48.         Dim sGroupID As Date
  49.         Dim hGroup As Long
  50.         Dim hFile As Long
  51.         Dim sEntryInfo As INTERNET_CACHE_ENTRY_INFO
  52.         Dim iSize As Long
  53.  
  54.         On Error Resume Next
  55.  
  56.         ' Delete the groups
  57.         hGroup = FindFirstUrlCacheGroup(0, 0, 0, 0, sGroupID, 0)
  58.  
  59.         ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
  60.         If Err.Number <> 453 Then
  61.             If (hGroup = 0) And (Err.LastDllError <> 2) Then
  62.                 MsgBox("An error occurred enumerating the cache groups" & Err.LastDllError)
  63.                 Exit Sub
  64.             End If
  65.         Else
  66.             Err.Clear()
  67.         End If
  68.  
  69.         If (hGroup <> 0) Then
  70.             'we succeeded in finding the first cache group.. enumerate and
  71.             'delete
  72.             Do
  73.                 If (0 = DeleteUrlCacheGroup(sGroupID, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, 0)) Then
  74.  
  75.                     ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
  76.                     If Err.Number <> 453 Then
  77.                         MsgBox("Error deleting cache group " & Err.LastDllError)
  78.                         Exit Sub
  79.                     Else
  80.                         Err.Clear()
  81.                     End If
  82.                 End If
  83.                 iSize = BUFFERSIZE
  84.                 If (0 = FindNextUrlCacheGroup(hGroup, sGroupID, iSize)) And (Err.LastDllError <> 2) Then
  85.                     MsgBox("Error finding next url cache group! - " & Err.LastDllError)
  86.                 End If
  87.             Loop Until Err.LastDllError = 2
  88.         End If
  89.  
  90.         ' Delete the files
  91.         sEntryInfo.dwStructSize = 80
  92.         iSize = BUFFERSIZE
  93.         hFile = FindFirstUrlCacheEntry(0, sEntryInfo, iSize)
  94.         If (hFile = 0) Then
  95.             If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then
  96.                 GoTo done
  97.             End If
  98.             MsgBox("ERROR: FindFirstUrlCacheEntry - " & Err.LastDllError)
  99.             Exit Sub
  100.         End If
  101.         Do
  102.             If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData)) _
  103.                 And (Err.LastDllError <> 2) Then
  104.                 Err.Clear()
  105.             End If
  106.             iSize = BUFFERSIZE
  107.             If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize)) And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then
  108.                 MsgBox("Error:  Unable to find the next cache entry - " & Err.LastDllError)
  109.                 Exit Sub
  110.             End If
  111.         Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS
  112. done:
  113.         MsgBox("Items cleared", , "Success!")
  114.     End Sub
  115.  
  116. End Module

and for the command inside the Form:
VB Code:
  1. Module1.Command1_Click()