Open Word doc from Access

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.
 
P

Perry

To avoid the read-only message, you cud base a new document off the original
..RTF document
like in:
Set objWordDoc = objWord.Documents.Add("C:\test.rtf")

But what I don't understand is that the reports are stored in folder
"c:\Grievance"
yet you want to open the RTF reports in c-root.
Why is this?

Krgrds,
Perry
 
D

Doug

Oops. That's a typo. Files will be opened from same
folder (c:\Grievance).

The problem with creating a new doc is that people will
be adding comments to the doc. These are not stored in
the db. In other words, once the original doc is created,
I would like to simply open the doc so that new comments
etc. could be added. What is stored in the db are the
specific facts plus the file num. All the other misc
stuff will be added to the doc.

Thanks for your suggestions.

Doug
-----Original Message-----
To avoid the read-only message, you cud base a new document off the original
..RTF document
like in:
Set objWordDoc = objWord.Documents.Add("C:\test.rtf")

But what I don't understand is that the reports are stored in folder
"c:\Grievance"
yet you want to open the RTF reports in c-root.
Why is this?

Krgrds,
Perry

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.


.
 
P

Perry

Yr users can adjust the RTF reports if you open them the way you
presented in yr initial msg as well.

The problem in this scenario is that yr original report gets dirty:

Creating a new document off the original one at least leaves the original
one untempered/

Krgrds,
Perry

Doug said:
Oops. That's a typo. Files will be opened from same
folder (c:\Grievance).

The problem with creating a new doc is that people will
be adding comments to the doc. These are not stored in
the db. In other words, once the original doc is created,
I would like to simply open the doc so that new comments
etc. could be added. What is stored in the db are the
specific facts plus the file num. All the other misc
stuff will be added to the doc.

Thanks for your suggestions.

Doug
-----Original Message-----
To avoid the read-only message, you cud base a new document off the original
..RTF document
like in:
Set objWordDoc = objWord.Documents.Add("C:\test.rtf")

But what I don't understand is that the reports are stored in folder
"c:\Grievance"
yet you want to open the RTF reports in c-root.
Why is this?

Krgrds,
Perry

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.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top