D
Doug
I have an Access database in which I create and convert a
report to a .rtf file in Word. If a user wants to create
an .rtf I want to check first that it doesn't exist. If
it does exist, then rather than creating a new file I
wish to open the existing file. All is fine except that I
cannot open the file. Sometimes it opens read-only, the
next time nothing happens or I get various error messages
seemingly with the same code. I figure that this should
be so simple. I'm obviously missing something. Here is
the code. Works fine until the open word doc part:
Private Sub CheckFile()
Dim sFileName As String, strFileNum As String,
strFileNumExists As String, strReport As String
Dim bFileExists As Boolean
strFileNumExists = [Forms]![F_GrievanceAddMaster].
[frmGrievanceAdd]![txtFileNum] & ".rtf"
strFileNum = "C:\Grievance\" & strFileNumExists
sFileName = Dir("C:\Grievance\")
strReport = "R_Grievances_WordRpt"
bFileExists = False
Do While sFileName <> ""
If sFileName = strFileNumExists Then
MsgBox "File found: " & strFileNum
bFileExists = True
'Open Word document
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Set objWord = CreateObject("Word.Application")
Set objWordDoc = objWord.Documents.Open
("C:\test.rtf", , False)
Exit Do
End If
sFileName = Dir ' Get next entry.
Loop
If bFileExists = False Then
'create word .rtf file
DoCmd.OutputTo acReport, strReport,
acFormatRTF, strFileNum, True
End If
End Sub
Any help would be great.
report to a .rtf file in Word. If a user wants to create
an .rtf I want to check first that it doesn't exist. If
it does exist, then rather than creating a new file I
wish to open the existing file. All is fine except that I
cannot open the file. Sometimes it opens read-only, the
next time nothing happens or I get various error messages
seemingly with the same code. I figure that this should
be so simple. I'm obviously missing something. Here is
the code. Works fine until the open word doc part:
Private Sub CheckFile()
Dim sFileName As String, strFileNum As String,
strFileNumExists As String, strReport As String
Dim bFileExists As Boolean
strFileNumExists = [Forms]![F_GrievanceAddMaster].
[frmGrievanceAdd]![txtFileNum] & ".rtf"
strFileNum = "C:\Grievance\" & strFileNumExists
sFileName = Dir("C:\Grievance\")
strReport = "R_Grievances_WordRpt"
bFileExists = False
Do While sFileName <> ""
If sFileName = strFileNumExists Then
MsgBox "File found: " & strFileNum
bFileExists = True
'Open Word document
Dim objWord As Word.Application
Dim objWordDoc As Word.Document
Set objWord = CreateObject("Word.Application")
Set objWordDoc = objWord.Documents.Open
("C:\test.rtf", , False)
Exit Do
End If
sFileName = Dir ' Get next entry.
Loop
If bFileExists = False Then
'create word .rtf file
DoCmd.OutputTo acReport, strReport,
acFormatRTF, strFileNum, True
End If
End Sub
Any help would be great.