Problem with browse for file

Last week an expert helped me with code that would allow the user to browse for a file.  But the Access database is an mdb file.  When I click on the [Select file] command button on the menu I get an error:

Compile Error:  Can't find project or library.

Here's the code:  Can someone help?

Private Sub cmdSelectFile_Click()

    Dim fd As FileDialog, SelectFolderOrFile
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .InitialFileName = Environ("userprofile") & "\Documents\"
        If .Show Then
            Me.txtFileName = .SelectedItems(1)
        End If
       
    End With

End Sub
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
add the Microsoft Office xx Object library to your references

xx is the office version that you are using
0
SteveL13Author Commented:
I added the only Microsoft Office Object Library I could find not checked...

Microsoft Office 14.0 Object Library.  I'm using Office 2010.

It still didn't work.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
You should also be able to do this

Replace

  Set fd = Application.FileDialog(msoFileDialogFilePicker)

with

  Set fd = Application.FileDialog(3)

You only need the Reference if you want to use the built in Constants. If you use their numeric equivalents, then you don't need the Reference.

mx
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

SteveL13Author Commented:
Here is what I have now.  But now I get:

Compile Error:  User-defined type not defined.



Private Sub cmdSelectFile_Click()

    Dim fd As FileDialog, SelectFolderOrFile
    Set fd = Application.FileDialog(3)
    'Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .InitialFileName = Environ("userprofile") & "\Documents\"
        If .Show Then
            Me.txtFileName = .SelectedItems(1)
        End If
       
    End With

End Sub
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Which line is the error on ?
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Also ... this is all the code you should  need:

    With Application.FileDialog(3)
        .InitialFileName = Environ("userprofile") & "\Documents\"
        If .Show Then
           Me.txtFileName = .SelectedItems(1)
        End If
    End With

It works for me ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
MX,

I thought that code was valid for Access 2003 or 2007 and newer?

For old MDB's wouldn't you still have to go with "old reliable"?
http://access.mvps.org/access/api/api0001.htm

Jeff
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
' I'm using Office 2010."
0
Jeffrey CoachmanMIS LiasonCommented:
k
;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.