Command button to open document.

Bird_FAT

Registered User.
Local time
Today, 14:14
Joined
Apr 8, 2009
Messages
30
[Solved] Command button to open document.

(Differences Noted in RED)

Can anyone tell me why if I use this code:
Code:
Private Sub OpenIAG_Click()
On Error GoTo Err_OpenIAG_Click

    Dim stAppName As String

    stAppName = "[U][COLOR=DarkRed][B]explorer.exe[/B][/COLOR][/U] " & "M:\Student_Files\My_Students\" & Forms!FrmStudentTracking.Form.Forename.Value & "_" & Forms!FrmStudentTracking.Form.Surname.Value & "\" & Forms!FrmStudentTracking.Form.Forename.Value & "_" & Forms!FrmStudentTracking.Form.Surname.Value & "_-_IAG.xls"
    Call Shell(stAppName, 1)

Exit_OpenIAG_Click:
    Exit Sub

Err_OpenIAG_Click:
    MsgBox Err.Description
    Resume Exit_OpenIAG_Click
        
End Sub
to call a file (M:\Student_Files\My Students\Stephen Jones\Stephen Jones - IAG.xls) I get a dialogue box asking if I want to open, save or cancel; yet if I use this code

Code:
Private Sub OpenIAG_Click()
On Error GoTo Err_OpenIAG_Click

    Dim stAppName As String

    stAppName = "[U][B][COLOR=DarkRed]excel.exe[/COLOR][/B][/U] " & "M:\Student_Files\My_Students\" & Forms!FrmStudentTracking.Form.Forename.Value & "_" & Forms!FrmStudentTracking.Form.Surname.Value & "\" & Forms!FrmStudentTracking.Form.Forename.Value & "_" & Forms!FrmStudentTracking.Form.Surname.Value & "_-_IAG.xls"
    Call Shell(stAppName, 1)

Exit_OpenIAG_Click:
    Exit Sub

Err_OpenIAG_Click:
    MsgBox Err.Description
    Resume Exit_OpenIAG_Click
        
End Sub
I get the message:

'M;\Student_Files\My_Students\Stephen_Jones\Stephen_Jones_-_IAG.xls' could not be found.

And if I remove the Underscores the message is similar but is broken at every space giving me 7 error messages.

Any ideas, folks?!

Cross posted here!
 
Last edited:
What is the object of the exercise?

Is it to enable the user to click on a student name and search in a specified folder for the existance of an Excel spreadsheet and if present open it in Excel?

David
 
What is the object of the exercise?

Is it to enable the user to click on a student name and search in a specified folder for the existance of an Excel spreadsheet and if present open it in Excel?

David


The object is to open an excel workbook based on the path given - the path is made up of the students name and IS present as the student area is created before the entries are added to the database.

All I'm looking to find out is why does it parse the information differently based on whether I reference explorer.exe or excel.exe.

Referencing explorer gives me
a dialogue box asking if I want to open, save or cancel.
Referencing excel gives me an error message saying it can't find the file.

Why? Any ideas?
 
Here is a simple demo that lists files in a specified folder with a specified extension. If you double click on the entry in the list it will open up in its native software.
 

Attachments

Here is a simple demo...

:DWho for - Einstien!:D

MAN! I'd hate to have to work through something you call complicated, dude!:eek:

If you double click on the entry in the list it will open up in its native software.

I love the way you use the *.dll to work out the default program to open the file, very neat!

I will work my way through the code involved, and this may take time as a lot of it is over my head - but that's the best bit, isn't it? The challenge?

Thanks a lot for the jump start DCrake!
 
Cross Post update

Also note that there was another solution posted here, on the cross post!


Thanks to all for the help!
 
Howzit

I picked this up somewhere along the way. Can't remember where or from who to give the kudos to.

File name (full path) held in a text box (Attach1), and a command button to open the document.


Code:
Private Sub cmdView1_Click()

Call OpenDocument(Me.Attach1)

End Sub


Code:
Public Sub OpenDocument(DocPath As String)
Dim A As Long
A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocPath, vbMaximizedFocus)
End Sub

This works for .xls,.doc, .pdf, .mdb. It probably works for others - just haven't tried any others.
 

Users who are viewing this thread

Back
Top Bottom