There's a better way to open a word document using the Windows API.
Copy this code to the top of your form/module under Option Compare Database...
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _ ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Copy this as a function in your form/module....
Private Sub OpenFile(File As String) On Error GoTo cmdOpenFile_Err 'open the document in whatever application it requires ShellExecute 0, "open", File, vbNullString, vbNullString, vbNormalFocus Exit Sub cmdOpenFile_Err: MsgBox "An unexpected error has occurred.", vbOKOnly + vbCritical, "Error Conditon in Opening File" End Sub
Then call....
OpenFile("C:\MyDocuments\MyWordDoc.doc")
This will cause word to open and the file to be displayed just as though someone double clicked the file. You don't need to know where word is stored as basically your asking windows to open the file for you.
This will work for images, pdf, any document at all.
They will all open in their default application.
www.dsmyth.net/blog |