kaisersose
Registered User.
- Local time
- Today, 01:14
- Joined
- Sep 25, 2008
- Messages
- 13
I have a form where a user has to fill out a number of fields, and then click the print button. Which will then export the data they just entered into a word file, print the word file and then go on to a new record in the form.
Now I want to make sure users fill out all fields. I want to have it so that when they click the print button, it will check that all fields are filled, and only then will it print out the word document. If they don’t have all fields filled out and they are prompted for each field they fail to fill. At the moment this is what I have:
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.Open("P:\ Test.doc", , True)
With doc
.FormFields("fldDate").Result = Me!Date
.FormFields("fldInitiator").Result = Me!Initiator
.FormFields("fldDescriptionofItem").Result = Me!Descriptionofitem
.FormFields("fldArea").Result = Me!Area
.Visible = True
.Activate
DoCmd.GoToRecord , , acNewRec
appWord.Documents.Open "P:\ Test.doc"
appWord.PrintOut Background:=False
appWord.Quit
End With
Set doc = Nothing
Set appWord = Nothing
End Sub
Function PrintDoc()
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
appWord.Documents.Open "P:\ Test.doc"
appWord.PrintOut Background:=False
appWord.Quit
Set WordObj = Nothing
End Function
Anyone have any pointers on what I need to do? (i'm only learning access atm
)
Now I want to make sure users fill out all fields. I want to have it so that when they click the print button, it will check that all fields are filled, and only then will it print out the word document. If they don’t have all fields filled out and they are prompted for each field they fail to fill. At the moment this is what I have:
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.Open("P:\ Test.doc", , True)
With doc
.FormFields("fldDate").Result = Me!Date
.FormFields("fldInitiator").Result = Me!Initiator
.FormFields("fldDescriptionofItem").Result = Me!Descriptionofitem
.FormFields("fldArea").Result = Me!Area
.Visible = True
.Activate
DoCmd.GoToRecord , , acNewRec
appWord.Documents.Open "P:\ Test.doc"
appWord.PrintOut Background:=False
appWord.Quit
End With
Set doc = Nothing
Set appWord = Nothing
End Sub
Function PrintDoc()
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")
appWord.Documents.Open "P:\ Test.doc"
appWord.PrintOut Background:=False
appWord.Quit
Set WordObj = Nothing
End Function
Anyone have any pointers on what I need to do? (i'm only learning access atm