Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Word Document 1

Status
Not open for further replies.

Knicks

Technical User
Apr 1, 2002
383
US
I have an interesting scenerio. I am converting Excel tables into an Access 2000 database. There are also Word documents that have a PO number embedded in their file name to the effect of Johnson 3456.doc, what I would like to do is have the ability to open a document where the PO field in my database matches anywhere in the string filename with a command button. The PO field is type Number.

So say the current record shows [po]=3456, the user if they needed to see the archived word document that has 3456 anywhere in the filename, have it open the Word doc when clicked

Any suggestions would be appreciated,
Thanx
 
Have an "View PO" button on the form....and lets say you PO Number field on this form is called "PONumber".

Now understand that my syntax may not be correct and that you will need to include the Reference (Tools/References) for your version of Word. However, as a starting point, the code should look something like this...

Code:
'Declare Word related object variables
Dim wapp as New Word.Application
Dim wdoc as Word.Document

Private Sub cmdViewPO_Click()
On Error Goto Err_cmdViewPO_Click

    'Filename search result
    Dim strFilename as String
    'Document Search String (*12345.doc)
    Dim strSearch as String

    'Where are the PO Word Docs stored on the network
    '  (must be a local drive or Mapped Network Drive)
    Const strPOPath as String = "F:\po\"

    strSearch = "*" & Cstr(Me.PONumber) & ".Doc"

    ChDrive Left$(strPOPath, 1)
    ChDir strPODocPath

    'Find the file
    strFilename = Dir(strSearch)

    If strFilename = "" Then

        MsgBox "Unable to find PO Document " & Me.PONumber, vbExclamation, "View PO...."
        Exit Sub

    End If

    'Open the document
    Set wdoc = wapp.OpenDocument(strPOPath & strFilename)

Exit_cmdViewPO_Click:
    Exit Sub

Err_cmdViewPO_Click:
    MsgBox Err.Description, vbCritical, "View PO : ERROR " & Err.Number
    Resume Exit_cmdViewPO_Click

End Sub

Private Sub Form_Close()

    Wapp.Quit
    Set wdoc = Nothing
    Set wapp = Nothing

End Sub
On On
Johnathan Perry
 
Thanx

This looks really good. I'll give it a try and let you know how it works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top