R
richardb
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
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