kaisersose
Registered User.
- Local time
- Today, 15:18
- Joined
- Sep 25, 2008
- Messages
- 13
I have an access form set up and when the user fills out all the fields, I want it to write the values from the fields to a word file, print the word file and then save the word file with a particular name (the value of the OrderID). I have it exporting to a word file at the moment and printing the word file, but the user is prompted to save the save the file and they have to have make sure they name the file the value of the OrderID.
Private Sub CmdPrint_Click()
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn’t open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Add("U:\test.doc", , True)
'Set doc = wApp.Documents.Add(Template:="U:\test.doc")
With doc
.FormFields("fldOrderID").Result = Me!OrderID
.FormFields("fldDate").Result = Me!Date
.FormFields("fldName").Result = Me!Name
.FormFields("fldAddress").Result = Me!Address
.Visible = True
.Activate
DoCmd.GoToRecord , , acNewRec
'appWord.Documents.Open "U:\test.doc"
appWord.PrintOut Background:=True
appWord.Quit
End With
Set doc = Nothing
Set appWord = Nothing
appWord.Documents.Close "U:\test.doc"
End Sub
Function PrintDoc()
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
appWord.Documents.Open "U:\test.doc"
appWord.PrintOut Background:=True
appWord.Quit
Set WordObj = Nothing
End Function
So basically what i want to do is, when the user fills out the form and clicks print, the data is added to the database, and the data is written to a word file, printed out and word file is automatically saved with the the value of the OrderID. And I want this to happen in the background so that the user doesnt even know all this happening. They will just collect the printed out sheet at the printer.
If anyone has any idea's on what needs to be done it would be appreciated.
Private Sub CmdPrint_Click()
Dim appWord As Word.Application
Dim doc As Word.Document
'Avoid error 429, when Word isn’t open.
On Error Resume Next
Err.Clear
'Set appWord object variable to running instance of Word.
Set appWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'If Word isn’t open, create a new instance of Word.
Set appWord = New Word.Application
End If
Set doc = appWord.Documents.Add("U:\test.doc", , True)
'Set doc = wApp.Documents.Add(Template:="U:\test.doc")
With doc
.FormFields("fldOrderID").Result = Me!OrderID
.FormFields("fldDate").Result = Me!Date
.FormFields("fldName").Result = Me!Name
.FormFields("fldAddress").Result = Me!Address
.Visible = True
.Activate
DoCmd.GoToRecord , , acNewRec
'appWord.Documents.Open "U:\test.doc"
appWord.PrintOut Background:=True
appWord.Quit
End With
Set doc = Nothing
Set appWord = Nothing
appWord.Documents.Close "U:\test.doc"
End Sub
Function PrintDoc()
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
appWord.Documents.Open "U:\test.doc"
appWord.PrintOut Background:=True
appWord.Quit
Set WordObj = Nothing
End Function
So basically what i want to do is, when the user fills out the form and clicks print, the data is added to the database, and the data is written to a word file, printed out and word file is automatically saved with the the value of the OrderID. And I want this to happen in the background so that the user doesnt even know all this happening. They will just collect the printed out sheet at the printer.
If anyone has any idea's on what needs to be done it would be appreciated.