Results 1 to 5 of 5
  1. #1
    HowardOfOcal is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Near Ocala Fl
    Posts
    5

    Why Doesn't Stuff Work Anymore?

    This worked great in Access 2003 to use the file open dialog box. Now I get an error message in Access 2010

    "Compile Error: User-defined type not defined"

    Is there another library I have to reference?

    -----------------------------------------------------------------------------------

    Private Sub GetfileName(SelectedFile, usercanceled As Boolean, Section As String, tFileDescription)

    ' This requires a reference to the Microsoft Office 11.0 Object Library.

    Dim fDialog As Office.FileDialog
    Dim varFile As Variant

    ' Set up the File dialog box.
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog


    ' Don't Allow the user to make multiple selections in the dialog box.
    .AllowMultiSelect = False

    ' Set the title of the dialog box.
    .Title = tFileDescription
    ' Clear out the current filters, and then add your own.
    .Filters.Clear
    .Filters.Add "Excell Spreadsheets", "*.*"

    ' Show the dialog box. If the .Show method returns True, the
    ' user picked at least one file. If the .Show method returns
    ' False, the user clicked Cancel.
    If .Show = True Then
    ' Loop through each file that is selected and then add it to the list box.
    For Each varFile In .SelectedItems
    SelectedFile = varFile
    usercanceled = False
    Next
    Else
    MsgBox "You clicked Cancel in the file dialog box."
    usercanceled = True
    End If
    End With
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Yes,

    ' This requires a reference to the Microsoft Office 11.0 Object Library.

    should be 14.0

    Open the VBA Editor Tools > References and make sure Office 14 is the selected library.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    The other way is to not use references at all and use what is known as LATE BINDING. The code modified to use Late Binding would be:
    Code:
    Private Sub GetfileName(SelectedFile, usercanceled As Boolean, Section As String, tFileDescription)
    
    ' This requires a reference to the Microsoft Office 11.0 Object Library.
    
    Dim fDialog As Object
    Dim varFile As Variant
    Dim Const msoFileDialogFilePicker As Integer = 3
    
    ' Set up the File dialog box.
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
    ' Don't Allow the user to make multiple selections in the dialog box.
    .AllowMultiSelect = False
    
    ' Set the title of the dialog box.
    .Title = tFileDescription
    ' Clear out the current filters, and then add your own.
    .Filters.Clear
    .Filters.Add "Excell Spreadsheets", "*.*"
    
    ' Show the dialog box. If the .Show method returns True, the
    ' user picked at least one file. If the .Show method returns
    ' False, the user clicked Cancel.
    If .Show = True Then
    ' Loop through each file that is selected and then add it to the list box.
    For Each varFile In .SelectedItems
    SelectedFile = varFile
    usercanceled = False
    Next
    Else
    MsgBox "You clicked Cancel in the file dialog box."
    usercanceled = True
    End If
    End With
    End Sub
    The only drawback is that intellisense doesn't work with late binding. So I usually use early binding (by setting the reference) until I have it the way I want and then change over to late binding for production and then when versions change there is no issue.

  4. #4
    HowardOfOcal is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Near Ocala Fl
    Posts
    5

    Smile

    Quote Originally Posted by boblarson View Post
    The other way is to not use references at all and use what is known as LATE BINDING. The code modified to use Late Binding would be:
    [code]
    Private Sub GetfileName(SelectedFile, usercanceled As Boolean, Section As String, tFileDescription)

    ' This requires a reference to the Microsoft Office 11.0 Object Library.

    Dim fDialog As Object
    Dim varFile As Variant
    Dim Const msoFileDialogFilePicker As Integer = 3
    Well, I rummaged around in the references list under tools and found a checkbox for "Microsoft Office 14 Object Library" I checked it and my problem went away :-)

    I understand the idea of early or late binding, but I'm not sure what the
    "Dim Const msoFileDialogFilePicker As Integer = 3" statement does. That's for another day of research.

    I hope I didn't screw anything else up by selecting the #14 library.

    I guess this case is closed. Thanks for the help.

  5. #5
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    No, you wouldn't have screwed anything up by selecting that reference. And the Dim Const is messed up. I errored - it should have just said

    Const msoFileDialogFilePicker As Integer = 3

    no DIM in front of it. So that was causing you to get an error.

    And the value of msoFileDialogFilePicer is 3 so that is what we were doing. When using late binding, constants need to be defined if you are using them as Access knows nothing about them if the reference isn't set.

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

Similar Threads

  1. Calling for parameter that doesn't exist anymore
    By rankhornjp in forum Programming
    Replies: 3
    Last Post: 12-22-2011, 02:14 PM
  2. Buttons doesn't work in Subforms
    By fedesc in forum Access
    Replies: 6
    Last Post: 09-25-2011, 12:58 AM
  3. App doesn't work with runtime
    By bubba55 in forum Access
    Replies: 0
    Last Post: 09-21-2011, 08:33 AM
  4. Can Grow doesn't work
    By gg80 in forum Reports
    Replies: 6
    Last Post: 05-13-2011, 07:14 PM
  5. Query doesn't work the day after
    By sithis876 in forum Queries
    Replies: 1
    Last Post: 07-13-2010, 07:11 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