Having access open a unique word document.

PuddinPie

Registered User.
Local time
Today, 01:56
Joined
Sep 15, 2010
Messages
149
Here's what I'm looking to try and do. I would like the EU to click a button and access 97 to make a new word file with the name based on a text field (ticket number) on the form. The veriables work fine but I'm not quite sure how to have it create a blank document.
Here's what I have so far.

Dim oApp As Object
Dim strFileName As String
Dim strFilePath As String

Set oApp = CreateObject("Word.Application")
strFileName = Me!txtTicketNumber & "Approval" & ""
strFilePath = "\\file-s1\iriseuc\rtm\97\EmailApproval\" & strFileName & ".doc"

' MsgBox's to see the output veriables
MsgBox strFileName
MsgBox strFilePath

' DoCmd.OutputTo acOutputForm, , acFormatRTF, "\\file-s1\iriseuc\rtm\97\EmailApproval\" & strFileName & "", True
oApp.Documents.Open (strFilePath)
oApp.Visible = True
 
To open a blank word doc use this (minus the greetings and salutations part of course).:
Code:
Dim oApp As Object
Dim strFileName As String
Dim strFilePath As String
Dim objDOC As Object
Dim objCurs As Object

'create the blank doc --> also shows how you can add some text there.
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set objDOC = oApp.Documents.Add
Set objCurs = oApp.selection
objCurs.typetext "Greetings and Salutations"

'asign the name from ye olde textbox. You could use a dialog here to pinpoint
'directory to save in by the user.
strFileName = Me!txtTicketNumber & "Approval" & ""
strFilePath = "C:\" & strFileName & ".DOC"

'save the document
objDOC.saveas (strFilePath)
This will have problems with not being able to use the same text in the textbox > 1 time. To overcome this use FSO, something like this:
Code:
Dim oApp As Object
Dim strFileName As String
Dim strFilePath As String
Dim objDOC As Object
Dim objCurs As Object

'create the blank doc --> also shows how you can add some text there.
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set objDOC = oApp.Documents.Add
Set objCurs = oApp.selection
objCurs.typetext "Greetings and Salutations"

'asign the name from ye olde textbox. You could use a dialog here to  pinpoint
'directory to save in by the user.
strFileName = Me!txtTicketNumber & "Approval" & ""
strFilePath = "C:\" & strFileName & ".DOC"

'check that it aint already there....
dim objFSO as object
set objFSO = createobject("Scripting.FileSystemObject")

if objFSO.fileexists(strfilepath) then
   dim strTimeStamp as string
   strTimeStamp = replace(Now," ","_")
   strTimeStamp = replace(strTimeStamp,":","")
   strTimeStamp = replace(strTimeStamp,"/","")
   strFilePath = "C:\" & strFileName & strTimeStamp & ".DOC"
end if

'save the document
objDOC.saveas (strFilePath)
 

Users who are viewing this thread

Back
Top Bottom