2

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?

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.