View Full Version : Open a document from Access


jiminic
09-25-2007, 03:47 PM
Hello everyone.

I am having a problem with my Access VBA. Using a button on my database, I want to open a Word document that has been created and named using the auto number system in Access (eg, auto number 3448, Word document name 3448.doc). I am using the following code:

Private Sub RetreiveScreenDumps_Click()

On Error GoTo Err_RetreiveScreenDumps_Click

Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE N:\SMDiv\Insurance\MemberRelations\FileManagement\ SystemReferrals\" & Forms![SystemReferralActionFrm]![SystemReferralTbl.JobNumber] & ".doc"

Call Shell(stAppName, 1)

Exit_RetreiveScreenDumps_Click:
Exit Sub

Err_RetreiveScreenDumps_Click:
MsgBox Err.Description
Resume Exit_RetreiveScreenDumps_Click

End Sub

The problem is, when Word opens I get an error message saying "The document name or path is invalid". I know there is a simple fix to this, but can not figure out what to do.

Any help would be greatly appreciated.

Guus2005
09-26-2007, 05:23 AM
Use createobject (F1)

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("c:\temp\aap.xls")

Example using Excel

DJkarl
09-26-2007, 05:54 AM
Hello everyone.

I am having a problem with my Access VBA. Using a button on my database, I want to open a Word document that has been created and named using the auto number system in Access (eg, auto number 3448, Word document name 3448.doc). I am using the following code:

Private Sub RetreiveScreenDumps_Click()

On Error GoTo Err_RetreiveScreenDumps_Click

Dim stAppName As String

stAppName = "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE N:\SMDiv\Insurance\MemberRelations\FileManagement\ SystemReferrals\" & Forms![SystemReferralActionFrm]![SystemReferralTbl.JobNumber] & ".doc"

Call Shell(stAppName, 1)

Exit_RetreiveScreenDumps_Click:
Exit Sub

Err_RetreiveScreenDumps_Click:
MsgBox Err.Description
Resume Exit_RetreiveScreenDumps_Click

End Sub

The problem is, when Word opens I get an error message saying "The document name or path is invalid". I know there is a simple fix to this, but can not figure out what to do.

Any help would be greatly appreciated.

Try

stAppName = chr$(34) & "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" & chr$(34) & " " & chr$(34)& "N:\SMDiv\Insurance\MemberRelations\FileManagement\ SystemReferrals\" & Forms![SystemReferralActionFrm]![SystemReferralTbl.JobNumber] & ".doc" & chr$(34)

Dennisk
09-26-2007, 06:03 AM
If you use shell execute you do not have to specify the path to Word.exe just the document name.