VB Shell Folder error handler
-
I have in my application a subroutine that opens a browse folder so that the user can browse to a specific directory, and load that into a text box. The code is like this: ...
Set shlShell = New shell32.Shell Set shlFolder = shlShell.BrowseForFolder(Me.hWnd, "Select a Folder", BIF_RETURNONLYFSDIR) textbox_txt.SetFocus textbox_txt.Text = shlFolder.Items.Item.Path 'places path into text box
Now, my problem is not when the user browses to a path and clicks OK, that returns the path of the directory fine. What the issue is, when the user clicks CANCEL, I get an error: runtime error '91' Object variable or With block not set. Any ideas on how I should handle this? Thanks. reegan41 -
I have in my application a subroutine that opens a browse folder so that the user can browse to a specific directory, and load that into a text box. The code is like this: ...
Set shlShell = New shell32.Shell Set shlFolder = shlShell.BrowseForFolder(Me.hWnd, "Select a Folder", BIF_RETURNONLYFSDIR) textbox_txt.SetFocus textbox_txt.Text = shlFolder.Items.Item.Path 'places path into text box
Now, my problem is not when the user browses to a path and clicks OK, that returns the path of the directory fine. What the issue is, when the user clicks CANCEL, I get an error: runtime error '91' Object variable or With block not set. Any ideas on how I should handle this? Thanks. reegan41Assuming you are using VB.Net You need to test the existence of shlFolder If Not IsNothing(shlFolder) Then process files End If However, you should really be using the .net directory and file info classes to achieve this with a directory browser dialog or openfile dialog!
Quote from Great Outdoors: its a confident traveller who farts in India