On click, file browser

Q1: Do you have code to open file browser to select a file?
Q2: And then code to open the file later using its full path?

I will then use the full path in a table.

Thank you.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
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.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Here you go:

Public Function msoFileFolderBrowse() As Boolean


    With Application.FileDialog(3) ' 3=msoFileDialogFilePicker
    .InitialFileName = "C:\AccessFilesAllVersions"    ' start in this folder
        .AllowMultiSelect = False
        .Show

        If .SelectedItems.Count > 0 Then
           MsgBox .SelectedItems(1)
        End If

    End With
   
'   Rey
'   Dim fDialog As Office.FileDialog, filenm As String
'   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
'   With fDialog
'        .Title = "Select File"
'        .InitialFileName = CurrentProject.path
'        If .Show Then
'        filenm = .SelectedItems(1)
'        End If
'
'   End With


'    With Application.FileDialog(3)  ' 3=msoFileDialogFilePicker
'        If .Show Then Debug.Print .SelectedItems(1)
'         more Code
'
'    End With
   

'    With Application.FileDialog(4)
'    .InitialFileName = "C:\SomeFolderName"    ' start in this folder
'        .AllowMultiSelect = False
'        .Show
'
'        If .SelectedItems.Count > 0 Then
'           MsgBox .SelectedItems(1)
'        End If
'
'    End With
'

'    With Application.FileDialog(4)  '4=msoFileDialogFolderPicker
'        If .Show Then Debug.Print .SelectedItems(1)
'        'more code
'    End With
   

End Function
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
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thanks,

Do you want me start a new post for Q2 I added later?
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Is this an Access db file ?

You can use the Shell command to open files with their default application (eg Access)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I am reading it again, sofar I have one error:

Private Sub lstFiles2_DblClick(Cancel As Integer)
'full path read successfully
MsgBox lstFiles2
Dim RetVal
'error at the following line: invalid procedure call or argument
RetVal = shell(lstFiles2) ', vbMinimizedFocus)

End Sub

Open in new window

0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I tried the following example from your link and that didn't work neither. I thing I need to look for code for Windows 8 not earlier.

' Specifying 1 as the second argument opens the application in 
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)    ' Run Calculator.

Open in new window

0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
So ... the Calculator did not open at all ?  Did anything happen ?
I can't imagine the Shell command has changed in Win 8. Shell has been around forever.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
With windows 10, the above code has the following error:calc I do not have access to Windows 8 to try. I think the error was the same from what I remember.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
in Windows 10, the following code works. Could you you give your shell version for me to try?
Set excel_app = New Excel.Application
    Set excel_wb = excel_app.workbooks.Open(Me!cboFolder.Column(1) & "\" & str_File, 0)
    excel_app.Visible = True

Open in new window

0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Well ... they must have changed the name of the Calculator EXE.

What about Notepad.exe ?

and back to this:

'full path read successfully
MsgBox lstFiles2
Dim RetVal
'error at the following line: invalid procedure call or argument
RetVal = shell(lstFiles2) ', vbMinimizedFocus)


Try just this

Shell (Chr(34) & lstFiles2 & Chr(34))

btw ... you don't need the RetVal ... you can just Shell by itself.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Calculator EXE   didn't work but Notepad.exe  worked.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
So there is some syntax issue with  lstFiles2
Can you post that path ?

And try this

Shell (Chr(34) & lstFiles2 & Chr(34))
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
using the following works:
Set excel_app = New Excel.Application
    Set excel_wb = excel_app.workbooks.Open(Me!cboFolder.Column(1) & "\" & str_File, 0)
    excel_app.Visible = True

Open in new window


But usingthe following doesn't:
Shell (Me!cboFolder.Column(1) & "\" & str_File)

'or
Dim RetVal
RetVal = Shell(Me!cboFolder.Column(1) & "\" & str_File, 0) ', vbMinimizedFocus)

'or
 Dim RetVal
RetVal = Shell(Me!cboFolder.Column(1) & "\" & str_File, vbMinimizedFocus)

Open in new window

fileOpen
Shell (Chr(34) & lstFiles2 & Chr(34)) didn't work.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Post the value of lstFiles2
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
C:\Users\Mike\Documents\EE\Excel_1.xlsx

btw, post your response at:

http://www.experts-exchange.com/questions/28709040/windows-8-open-a-file-vba-Access.html
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Sub OpenFile()

Application.FollowHyperlink "C:\Users\Mike\OneDrive\Documents\_MME_Programing\SQl_Server\70-461Book\666054eBook.pdf"

'and:

Application.FollowHyperlink "C:\Users\Mike\OneDrive\Documents\_MME_Programing\SQl_Server\70-461Book\70-461Summary.docx"

'and

Application.FollowHyperlink "C:\Users\Mike\Documents\EE\Excel_1.xlsx"
End Sub
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.