Reputation: 10971
I am trying to update an VBA module to use the System.Windows.Forms.FolderBrowserDialog
class. I declared my object as follows:
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
Running this gave me the error User-defined type not defined
. I figured the compiler didn't know about that class so I tried going to Tools > References
and adding Systems_Windows_Forms
, but I'm still getting the same error. Does anyone know what I'm missing here? Do I need a reference to the library in my code as well?
Upvotes: 2
Views: 4428
Reputation: 97101
System.Windows.Forms.FolderBrowserDialog
looks like something from .Net
to me, not VBA.
You can use Application.FileDialog
in Access VBA. This sample uses late binding and allows the user to select a folder from a browse dialog.
Const msoFileDialogFolderPicker As Long = 4
Dim objFileDialog As Object ' FileDialog
Set objFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
With objFileDialog
.AllowMultiSelect = False
If .Show Then
Debug.Print .SelectedItems(1)
End If
End With
If you prefer to use early binding, set a reference to the Microsoft Office [version] Object Library. You could then declare the object like this ...
Dim objFileDialog As FileDialog
And you wouldn't need to define the constant, so discard this line if using early binding ...
Const msoFileDialogFolderPicker As Long = 4
Upvotes: 3