Open or Create word document from within Access



I have attempted to write a routine in Access that will test if a Word file
exists; create if it does not exist; then open it for editing. I can't quite
get it. I get the error message "Invalid use of New keyword." (I attached the
Word 11 Object Library). I would appreciate if someone wouldn't mind
debugging this for me.

Public Function OpenFile(strFileName As String)

Dim wrd As Word.Application
Dim doc As Document
Dim strFilePath As String
Dim strDocument As String

strFilePath = Trim(varLookup("Lookup", "tlkpStoredStrings", "VariableName =
'DocDir'")) 'varlookup is a replacement for DLookup.
strDocument = strFilePath & "/" & strFileName & ".DOC"
On Error GoTo Err_Exit

' make sure both files exist
If (Not bolFileExists(strDocument)) Then
' create new empty document
Set doc = New Document
doc.SaveAs FileName:=strDocument
Else
Set doc = strDocument
End If
doc.Open

Exit_Proc:
Set doc = Nothing
Exit Function

Err_Exit:
MsgBox "Procedure: AppendFile" & vbCrLf & "Error Number: " & Err.Number
& vbCrLf & Err.Description, vbCritical, "UNEXPECTED ERROR"
OpenFile = False
Resume Exit_Proc

End Function

.



Relevant Pages

  • Re: Open or Create word document from within Access
    ... Public Function OpenFile(strFileName As String) ... 'use the Open method for an existing file ... Set doc = wrd.Documents.Open ... This reply is posted in the Newsgroup; please post any follow question or reply ...
    (microsoft.public.office.developer.automation)
  • Re: Open or Create word document from within Access
    ... > Public Function OpenFile(strFileName As String) ... > Dim strFilePath As String ... > 'use the Open method for an existing file ... > Set doc = wrd.Documents.Open ...
    (microsoft.public.office.developer.automation)
  • Extracting styles from Word using VB6
    ... build an array of the styles used and write a TXT file. ... Below is the code I've written so far, processing the Word file character by ... ' Style As String ' ID string in ... Dim HNum As Integer ' Count of number of elements in H array ...
    (microsoft.public.word.vba.general)
  • Extracting styles from a Word file with VB6
    ... build an array of the styles used and write a TXT file. ... Below is the code I've written so far, processing the Word file character by ... ' Style As String ' ID string in ... Dim HNum As Integer ' Count of number of elements in H array ...
    (comp.lang.basic.visual.misc)
  • RE: trim function with date inserted
    ... you can take the last two digits of the year with the Mid ... Function PadZeroAs String ... > mm/dd/yyyy format. ... How can I reformat date to be acceptable for word file ...
    (microsoft.public.access.forms)

Loading