Results 1 to 6 of 6
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Post Get Error but don't understand what I am doing wrong

    Hello all,



    I am getting a compile error, "User defined type not defined" on the following code, on the Dim fDialog As Office.FileDialog line. I got this code from a video to open a file dialog window to search for a file. I have tried to different versions of the code from 2 different sources and get the same error on the same line. What am I missing?

    Private Sub cmdAddLogo_Click()


    On Error GoTo SubError
    'Add "Microsoft Office 16.0 Object Library" in references
    Dim fDialog As Office.FileDialog
    Dim varFile As Variant

    txtSelectedName = ""

    ' Set up the File Dialog
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

    With fDialog
    .Title = "Choose the Image you would like to Use"
    .AllowMultiSelect = False
    ' .InitialFileName = "C:\Users\ray\Desktop\Export to Excel" 'Folder picker needs trailing slash

    .Filters.Clear
    ' .Filters.Add "Excel files", "*.xls*"
    ' .Filters.Add "Excel files", "*.xls"
    ' .Filters.Add "Excel files", "*.xlsx"
    ' .Filters.Add "Excel macro-enabled", "*.xlsm"

    If .Show = True Then
    If .SelectedItems.Count = 0 Then
    'User clicked open but didn't select a file
    GoTo SubExit
    End If

    'An option for MultiSelect = False
    'varFile = .SelectedItems(1)
    'txtSelectedName = varFile

    'Needed when MultiSelect = True
    For Each varFile In .SelectedItems
    txtSelectedName = txtSelectedName & varFile & vbCrLf
    Next
    Else
    'user cancelled dialog without choosing!
    'Do you need to react?
    End If

    End With

    SubExit:
    On Error Resume Next
    Set fDialog = Nothing
    Exit Sub

    SubError:
    MsgBox "Error Number: " & Err.Number & " = " & Err.Description, vbCritical + vbOKOnly, _
    "An error occurred"
    GoTo SubExit


    End Sub



    Thanks in Advance

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    I think you need to add "Microsoft Office 16.0 Object Library" to your list of references.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Bob,

    Yes, I thought I had it in there but I was looking at "Microsoft Access 16.0 Object Library" instead and thinking it was "Microsoft Office 16.0 Object Library". I added the "Microsoft Office 16.0 Object Library" and all is good now. Thank You

    Thanks

    Dave

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Glad you got it working
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Unable to delete post?

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by Dave14867 View Post
    Bob,

    Yes, I thought I had it in there but I was looking at "Microsoft Access 16.0 Object Library" instead and thinking it was "Microsoft Office 16.0 Object Library". I added the "Microsoft Office 16.0 Object Library" and all is good now. Thank You

    Thanks

    Dave

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Don't understand the error message
    By PATRICKPBME in forum Queries
    Replies: 3
    Last Post: 10-11-2019, 06:08 AM
  2. Replies: 6
    Last Post: 01-04-2018, 08:29 PM
  3. code error I don't understand why
    By LaughingBull in forum Access
    Replies: 5
    Last Post: 06-21-2017, 06:01 PM
  4. Replies: 5
    Last Post: 07-10-2013, 05:07 AM
  5. Replies: 2
    Last Post: 07-11-2011, 05:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums