PDA

View Full Version : [SOLVED:] Help with a loop error



gibbo1715
02-18-2005, 02:24 PM
Can anyone tell me why im getting the error loop without do in the code below ?




Dim fso As Object, _
ShellApp As Object, _
File As Object, _
SubFolder As Object, _
Directory As String, _
Problem As Boolean, _
ExcelVer As Integer
On Error Resume Next
Me.ListBox1.Clear
Application.ScreenUpdating = False
Set fso = CreateObject("Scripting.FileSystemObject")
Do
Problem = False
Set ShellApp = CreateObject("Shell.Application"). _
Browseforfolder(0, "Please choose a folder", 0, "")
On Error Resume Next
Directory = ShellApp.self.Path
Set SubFolder = fso.GetFolder(Directory).Files
If Err.Number <> 0 Then
If MsgBox("You did not choose a valid directory!" & vbCrLf & _
"Would you like to try again?", vbYesNoCancel, _
"Directory Required") <> vbYes Then
Unload Me
Exit Sub
Problem = True
End If
On Error GoTo 0
Loop Until Problem = False <<<< error here
ListBox1.RowSource = ""
For Each File In SubFolder
If Right(File.name, 3) = "doc" Then _
Me.ListBox1.AddItem Left(File.name, Len(File.name) - 4)
Next File
FileDir = Directory
Application.ScreenUpdating = True

Ken Puls
02-18-2005, 02:39 PM
Hi there,

Your IF block is not closed just above that:


If Err.Number <> 0 Then
If MsgBox("You did not choose a valid directory!" & vbCrLf & _
"Would you like to try again?", vbYesNoCancel, _
"Directory Required") <> vbYes Then
Unload Me
Exit Sub
Problem = True
End If
End If
On Error GoTo 0
Loop Until Problem = False

HTH,

gibbo1715
02-18-2005, 02:42 PM
you know that was the first thing i looked for and i still didnt see it, time to give up and goto bed i recon, many thanks

Ken Puls
02-18-2005, 02:44 PM
:giggle

Believe me, I undestand! It's bitten me before. Sometimes it's just easier for someone else to see it!

:beerchug: