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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Word document from Access form

Status
Not open for further replies.

Lightlancer

Programmer
Jul 18, 2008
88
NL
Hi all,

In a form i have a Hardwarenumber and in a subform a subnumber


Mainform:

Field: [Hardwarenumber]

Subform

Field: [Subno]


Now when a user clicks on a button, VBA must decide wich document to open (he must open a usermanual dedicated to the hardwarenumber)

I already tried something with this code i found somewhere on tektips

Code:
Private Sub Command19_Click()
On Error GoTo Err_Command19_Click
    ' Button launches Word and opens a specified document
    ' And runs an optional macro. the macro could print out the word doc and quit
    
    Dim retval As Variant
    Dim DocName, MacroName As String
    ' Drive and Full path to name and location of Word document
    DocName = "F:\Somefolder\ me.hardwarenumber & me.subChange.form!subno"
    
    'Optional Macro Name. Note Word Macro name cannot have any spaces in it.
    'MacroName = "/M" & "MacroName"
    
    'Note full path to Word including Drive and folder
    retval = Shell("c:\Microsoft Office97\office\WinWord.exe" & " " & DocName & MacroName, vbNormalFocus)

Exit_Command19_Click:
    Exit Sub

Err_Command19_Click:
    MsgBox Err.Description
    Resume Exit_Command19_Click
    
End Sub

but this doesnt work.........

so, the path to the files are U:\Manuals\
and the files are named *****.***.doc

Like: 00075.002.doc

where, 00075 = [hardwarenumber]
and
002 = subno

VBA must put a . between the 2 fields and add .doc.
offcourse before this must be: U:\Manuals\

How can i do this,
if someone can give the right solution..... that person deserves a star:D


Greetz

Lightlancer


P.S. if more info is needed, Please ASK!:D



 
DocName = "F:\Somefolder\ me.hardwarenumber & me.subChange.form!subno"

should be

DocName = "F:\Somefolder\" & [hardwarenumber] & [other_control_name] & ".doc"


but I'd try hard-coding a filename first to make sure the rest of your code is up to snuff, then throw the variables into the mix. ie,

DocName = "C:\somefile.doc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top