Open Word file, using database location

FFever

New member
Local time
Today, 16:59
Joined
Aug 11, 2004
Messages
6
Please, someone help me :o

I have created a table including a column "Invoice number". Softcopy invoices are in the same directory as the database is. By using a form, I would like to open the softcopy invoice. Can I link the invoice number to the softcopy invoice, by using the current database location? I would like to able to click the Invoice number and open the softcopy invoice.

Please help me ..



FFever
 
Does your table store the path and file Name (including extension) of each doc? (ie. C:\MyDocs\Doc1.doc)

If so, put the following in the OnClick event of a button on the form containing the text box that holds the path and file Name, changing 'YourTextBox' to the TextBox Name....
Code:
Application.FollowHyperlink [YourTextBox]
HTH
 
When I use the code below, I get the message "Microsoft Access can't find the macro 'Application'."

Application.FollowHyperlink [YourTextBox]

What am I doing wrong?

Fred.
 
You need to place the code in the VBA editor. In the OnClick of the button select 'Event Procedure' and then click the "..." button to the right, this will open the editor. Place the code between the two lines of code already generated. It should look something like this...
Code:
Private Sub YourButton_Click()

    Application.FollowHyperlink Me.YourTextBox
    
End Sub
obviously 'YourButton' will be the Name of your button on the form.

HTH
 
That works great ! Thanks
However, is it also possible to use the location of the database in code, so I only have to upload the invoice number (without path). When I place this on a CD-Rom, the drive is not always the same, so it should use the location of the database.

Fred.
 
The following code is what I use to return the current Db location;

Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name)))

So if you have the file name stored in your Db then the line would be

Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & Me.txtFileName

or

Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "report.doc"

To open word automatically from a cmd button click:


Dim objword As Object
Dim strFile as String
Set objword = CreateObject("Word.Application")

strFile = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & "report.doc"

objword.Visible = True
objword.Documents.Open strFile


Hope this is clear.

Dave
 
Thanks ! This solves my location problem, but makes me less flexible in using different format, like PDF or xls. Do I have to set possible codes for various format in the code like below ?

Dim objword As Object
Dim strFile As String
Set objword = CreateObject("Word.Application")

strFile = Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & [Invoice_Number] & [Format]

objword.Visible = True
objword.Documents.Open strFile


My clients use either pdf or word documents, so I need to be flexible.

Fred.
 
Code to open a PDF: (me.FilePath) is the path to the document stored in access)

Dim strProg As String
Dim strFile As String

'Open File

strProg = "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe"
strFile = Me.FilePath

If fIsFileDIR(strFile) = -1 Then
Call Shell(strProg & " " & strFile, vbMaximizedFocus)
Else
MsgBox "File cannot be found. Please check the file path. ", vbExclamation
End If
 
Code to open Excel: (me.QuoteWorkout) is the path to the excel spreadsheet stored in access)

Dim XL As Object
Set XL = CreateObject("Excel.Application")

If IsNull(Me.QuoteWorkout) Then
MsgBox "You haven't Attached a Calculation File", , " Service Operations"
Else

With XL.Application
.Visible = True
.workbooks.Open Me.QuoteWorkout

End With

Set XL = Nothing

End If
 
I would suggest performing a select case based on the file extension. I has code some where, I will get back to you.

Dave
 

Users who are viewing this thread

Back
Top Bottom