MS Access open Word
stokh | Posted 8:52am 7. March 2003 Server Time |
I need to have a command button Open a word template and insert that current record into the document for printing and I cant seem to find anything on the web that will simply explain to me on how to do this.
Click Button
open word template
insert the exact information on the Access Form into the word document
print the document,
save the record and close the form.
Can anyone tell me where to find this information?
Thanks!
Stokh |
enigma | Posted 11:26am 7. March 2003 Server Time |
stokh,
I've never had the need for something like this. Humm... have you looked into creating the actual document in HTML format and then renaming the file to a .doc extension? I know that Word (just like Excel) correctly displays HTML documents - the .doc extension would just force the viewing end user to open it by its default application (in this case WinWord).
I may be jumping the gun here in the hopes that you're creating the document and not using an existing Word document or template to insert the data in.
Anyone knows how to accomplish this?
enigma
enigma | Posted 11:43am 7. March 2003 Server Time |
stokh,
The first two URLs should give you the necessary knowledge on how to accomplish your task. I found the third to be a guide/reference from the msdn web. I know how accomplish using Adobe pdfdocuments but not MSWord. I'll give this a try and see how it works for me!
http://www.databaseadvisors.com/newsletters/0207wordautomationlpt1.htm
http://www.databaseadvisors.com/newsletters/0207wordautomationpt2.htm
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrMicrosoftWord2000.asp
enigma
stokh | Posted 11:50am 7. March 2003 Server Time |
Thanks I will try them all. Here is the code I have thus far. I need it to OPEN a TEMPLATE because these are official letters from us and play a significant part in someones life. Therefore html isnt an option at this point.
'code
Private Sub PrintCommandButton_Click()
On Error GoTo Err_PrintCommandButton_Click
Dim intMsgBoxResult As Integer
intMsgBoxResult = MsgBox("Are you ready to SAVE and PRINT this record?", vbYesNo + _
vbQuestion, "System Question")
If intMsgBoxResult = vbYes Then
Dim oApp As Object
Set oApp = GetObject(, "word.application")
If Err.Number <> 0 Then
Set oApp = CreateObject("Word.Application")
End If
oApp.Visible = True
Set doc = wrdApp.Documents.Open("NoRecordVrs1_03032003.dot")
Exit_PrintCommandButton_Click:
Exit Sub
Err_PrintCommandButton_Click:
MsgBox Err.Description
Resume Exit_PrintCommandButton_Click
End If
End Sub
okay then I went to MSDN and got this code for a module which seems to work if if I test it in the imtermediate window.
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("NoCanTell_03032003.dot", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as NoCanTell database.
objWord.MailMerge.OpenDataSource _
Name:="NoCanTell.lnk", _
LinkToSource:=True, _
Connection:="TABLE tblMainQID", _
SQLStatement:="SELECT * FROM [tblMainQID]Where ValidationNumber = &ValidationNumber"""
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
which opens the form and the correct one. but how do I modify the code to get the current record that is open in the Form Window? If I can get that figured out ahhhhh that would make my day!
Thanks
Stokh
stokh | Posted 10:09am 17. March 2003 Server Time |
Okay I finally get to get back to this project and I have the MailMerge figured out. But for some reason the code doesnt want to work for printing out the document from word and no matter what I do I cant get it figured out.
Private Sub OpenMailMerge_Click()
Dim objWord As Word.Application
Dim doc As Word.Document
Set objWord = CreateObject("word.application") 'Create an instance of Word
objWord.Visible = True 'Make sure you can see it!!
objWord.WindowState = wdWindowStateMaximize 'Maximize it, otherwise is always about 1/4 of screen
'Open a document based on a template for merging
objWord.Application.Documents.Add Template:="C:\Documents and Settings\XXXX.XXX-XXX\Desktop\RecordVrs1_03172003.dot", NewTemplate:=False
'Store name of document for later use
varDocName = objWord.ActiveDocument.Name
'Execute the mailmerge
objWord.ActiveDocument.MailMerge.Execute
'print the document to back ground so word wont close before printing
objWord.ActiveDocument.PrintOut Background:=False
'OpenMailMerge_Err
'if a field on the form is empty remove and merge
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
'Close the original document without saving it, leave the new document on screen
objWord.Documents(varDocName).Close SaveChanges:=wdDoNotSaveChanges
'Remove the Word object variable from memory
Set objWord = Nothing
End Sub
This is the line that gives the error of:
'code
objWord.ActiveDocument.PrintOut Background:=False
'Error:
Run-Time error -2147417851
Automation Error
The server threw an exception.
Any one have any ideas?
Thanks
Stokh
pussy cat | Posted 7:45am 18. March 2003 Server Time |
objWord.PrintOut false
pussy cat | Posted 7:48am 18. March 2003 Server Time |
objWord.ActiveDocument.PrintOut false
also works for me in office 2k
is the documet / application closing b4 the printjob has finished?? i had probs with this
stokh | Posted 10:45am 19. March 2003 Server Time |
I got it all here is the code I am using:
Private Sub OpenMailMerge_Click()
Dim intMsgBoxResult As Integer
intMsgBoxResult = MsgBox("Are you sure your ready to SAVE and PRINT this record?", vbYesNo + _
vbQuestion, "System Question")
If intMsgBoxResult = vbYes Then
DoCmd.Save
End If
intMsgBoxResult = MsgBox("Is there Letterhead in the printer?", vbYesNo + _
vbQuestion, "System Question")
If intMsgBoxResult = vbYes Then
Dim objWord As Object 'declare word object variables etc
Dim varDocName As String
Dim SQLstring As Variant
Dim strConnect As String
Set objWord = CreateObject("word.application") 'Create an instance of Word
objWord.Visible = True 'Make sure you can see it!!
objWord.WindowState = wdWindowStateMaximize 'Maximize it, otherwise is always about 1/4 of screen
'Open a document based on a template for merging
objWord.Application.Documents.Add Template:="PathToYourDocument\YourTemplateName.dot", NewTemplate:=False
'Store name of document for later use
varDocName = objWord.ActiveDocument.Name
'Execute the mailmerge
On Error Resume Next
objWord.ActiveDocument.MailMerge.Execute
'objWord.ActiveDocument.Options.PrintOut = True
'OpenMailMerge_Err
'if a field on the form is empty remove and merge
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If
'Close the original document without saving it, leave the new document on screen
objWord.Documents(varDocName).Close wdDoNotSaveChanges 'which will ask the userwdDoNotSaveChanges
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
'Quit MS Word
objWord.Quit
'Remove the Word object variable from memory
Set objWord = Nothing
Me.Form.SetFocus
DoCmd.Close
Else
If intMsgBoxResult = vbNo Then
DoCmd.CancelEvent
End If
End If
End Sub
Thanks!
Stokh
zlatan24 | Posted 12:07am 21. July 2010 Server Time |
MS Word documents are interesting. Reason of for example I frequently work with such files. And I must confess sometimes I have the problem and very big problems. But to my good fortune I got - [url=http://www.recoverytoolbox.com/how_to_recover_corrupt_doc_file.html]recovery toolbox per word[/url] on the Inet. It determined my issues quite simply and for free as I kept in mind.
zlatan24 | Posted 12:07am 21. July 2010 Server Time |
MS Word documents are interesting. Reason of for example I frequently work with such files. And I must confess sometimes I have the problem and very big problems. But to my good fortune I got - <a href="http://www.recoverytoolbox.com/how_to_recover_corrupt_doc_file.html">recovery toolbox per word</a> on the Inet. It determined my issues quite simply and for free as I kept in mind.
Reply to Post MS Access open Word
|
|
|