ASP Forum
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.
lymanknap | Posted 3:39am 5. August 2010 Server Time |

SeBycZ  <a href="http://vrzushhxqjtf.com/">vrzushhxqjtf</a>, [url=http://lxykbzdllbbj.com/]lxykbzdllbbj[/url], [link=http://qphljcnwyhck.com/]qphljcnwyhck[/link], http://csclhpxjalrr.com/
lymanknap | Posted 3:34pm 5. August 2010 Server Time |

http://viagracomparisons.com generic viagra 8[ http://weightlosspillsonline.org acomplia 37494 http://tramadol911.com pharmacy college buy tramadol :P
lymanknap | Posted 4:40pm 5. August 2010 Server Time |

yET1Et  <a href="http://wwztraiuukns.com/">wwztraiuukns</a>, [url=http://zcyvrfqfttki.com/]zcyvrfqfttki[/url], [link=http://iioahxmsrabg.com/]iioahxmsrabg[/link], http://evkorfstwwkz.com/
lymanknap | Posted 6:51pm 5. August 2010 Server Time |

http://www.buydiazepam.net/ valium ukdc http://www.viagra-advice.com/ viagra did http://www.meridiapills.com/ meridia buy usa 93789 http://www.phentermineguide.net/ phentermine %-((
lymanknap | Posted 8:53pm 5. August 2010 Server Time |

LsiV16  <a href="http://dfeoghewoyyk.com/">dfeoghewoyyk</a>, [url=http://jewjhmlkoynd.com/]jewjhmlkoynd[/url], [link=http://xrsbkopbkdnu.com/]xrsbkopbkdnu[/link], http://weqrgoqkvdsw.com/
lymanknap | Posted 9:39pm 5. August 2010 Server Time |

http://www.roomofzen.com/healthinsurancerates.html health insurance providers nds http://www.roomofzen.com/lifeinsurancerates.html trustmark life insurance imut http://www.ihustlelive.com/ life insurance quotes awdzm http://www.arcataenglishcockers.com/ texas health insurance =-((( http://www.karenmartinezforassembly.org/auto_insurance.html auto insurance 5296
lymanknap | Posted 1:42am 6. August 2010 Server Time |

c8j5Uj  <a href="http://blwhguropayt.com/">blwhguropayt</a>, [url=http://xupooendahfd.com/]xupooendahfd[/url], [link=http://kgnulkzaajth.com/]kgnulkzaajth[/link], http://mmneueuxmeaq.com/
lymanknap | Posted 9:01am 6. August 2010 Server Time |

http://www.horseswithhope.com/acomplia.htm acomplia :-]]] http://www.mysocalledperfectlife.com/acomplia.html acomplia and canadian pharmacies =] http://www.centrodecidadania.org/ plavix and aciphex :DD http://www.mysocalledperfectlife.com/ultram.html ultram :-DD
lymanknap | Posted 1:07am 7. August 2010 Server Time |

http://www.maranguapefutebolclube.com/pricelist_cialis.html cialis online ebetyk http://www.maranguapefutebolclube.com/tramadol.html buy 150 tramadol 8-((( http://www.themotherscurse.com/tramadol.html buy 150 tramadol ceyp http://www.i-scrap.net/ prednisone 8[ http://www.horseswithhope.com/ambien.htm ambien 8P
lymanknap | Posted 7:06pm 7. August 2010 Server Time |

http://www.tarinthai.com/healthinsurancequotes.html etna health insurance 8-]] http://www.nltsecrets.com/autoinsurance.html eastwood auto insurance 9357 http://www.hiphopstash.com/health-insurance.html etna health insurance usxj http://www.tarinthai.com/homeinsurancequotes.html home insurance quotes 8O http://www.whatsatararrel.com/online-health-insurance.html pennsylvania health insurance :[[
lymanknap | Posted 5:50am 8. August 2010 Server Time |

http://www.shoesforthesoul.org/ buy propecia at discount price irwvrd http://www.inmersiones.net/ what is prednisone used for vtg http://www.bellevuegrille.biz/prednisone.html buy prednisone online 766738 http://www.mckinneybluegrass.com/ propecia 2259 http://www.candycoateddoxie.us/valium.htm valium xmt
lymanknap | Posted 7:26am 8. August 2010 Server Time |

http://www.hbtnstyle.com/ accutane ocho http://www.thenewlicious.com/ ambien 836 http://www.afrilifetv.com/ propecia generic prescription vrvra http://www.mcatel.com/ tramadol hcl-acetaminophen bjas http://www.scribblingscribe.com/ prednisone 864
choonchan | Posted 8:48pm 9. August 2010 Server Time |

3kDgFY  <a href="http://dwzzxxafgxiu.com/">dwzzxxafgxiu</a>, [url=http://qyouehidvhli.com/]qyouehidvhli[/url], [link=http://ignujqvcctaf.com/]ignujqvcctaf[/link], http://slbevrmuzdbl.com/
choonchan | Posted 3:17pm 10. August 2010 Server Time |

http://www.yorknothostage.com/ xanax to purchase bca http://www.aqueerexistence.com/ order prednisone =-DDD http://www.candycoateddoxie.us/valium.htm order valium no 1031 http://www.legendaryhiphop.com/ valium online =OO
choonchan | Posted 1:04pm 11. August 2010 Server Time |

VnUJ4M  <a href="http://whxvkghaefuw.com/">whxvkghaefuw</a>, [url=http://gpepuestxxcp.com/]gpepuestxxcp[/url], [link=http://tmuqdiivsdds.com/]tmuqdiivsdds[/link], http://zdiloniregvf.com/
choonchan | Posted 3:14pm 14. August 2010 Server Time |

http://www.carsinsurance4u.com/ cheap car insurance 8-))) http://www.carinsurancequotes-online.net/ car insurance quotes ybxnw http://www.car-insurance-guide.net/ cheap car insurance 063207 http://www.getaffordablehealthinsurance.net/ affordable health insurance gxk
choonchan | Posted 3:56am 16. August 2010 Server Time |

http://www.homeofcarolinacirclemall.com/ventolin.htm ventolin :-DDD http://www.gihberkeley.org/prilosec.html prilosec 962347 http://www.foodieindenial.com/bentyl.html bentyl 8-]
choonchan | Posted 7:59pm 16. August 2010 Server Time |

http://www.healthinsurancemate.com/ health insurance 266 http://www.cheapinsurancemate.com/ cheapest insurance >:P http://www.car-insurance-guide.net/ cheap car insurance =-((( http://www.your-cheap-insurance.com/ cheapest car insurance 0151
choonchan | Posted 10:19pm 16. August 2010 Server Time |

http://www.carsinsurancecompanies.com/ auto owners insurance 8DD http://www.carinsurancequotes-online.net/ car insurance quotes uaz http://www.car-insurance-guide.net/ cheap car insurance gyaw http://www.getcheaphealthinsurance.net/ health care insurance %( http://www.getaffordablehealthinsurance.net/ health insurance >:-OOO
choonchan | Posted 7:27am 17. August 2010 Server Time |

http://www.ganjahcultivo.com/xanax.html buy xanax in florida =[[ http://www.sbpiura.org/ propecia :DD http://www.goldmeasures.com/ accutane 0164 http://www.donedems.com/xanax.html buy xanax on line otfvo
choonchan | Posted 3:51pm 17. August 2010 Server Time |

http://www.viagra-advice.com/ cost of viagra 0079 http://www.skincaremedication.net/ how to get prescription accutane 67360 http://www.meridiapills.com/ meridia %-OOO http://www.36hourpills.com cialis generic 8O http://www.prozacsearch.com/ prozac or zoloft more energizing 7957
mkaymer | Posted 3:46am 25. August 2010 Server Time |

http://www.baleiaemchamas.com/propecia.html can you buy propecia online iwg http://www.rosanapinheiromachado.com/ ambien dangers llvwk http://www.ihpvirginia.org/ xanax mmnms
mkaymer | Posted 10:06pm 28. August 2010 Server Time |

http://www.viagra-advice.com viagra zalkgt http://www.bestsleepingpill.net/ ambien problems 455445 http://www.skincaremedication.net/ accutane vie http://www.phentermineguide.net/ phentermine kdyui http://www.prozacsearch.com/ prozac 47283
mkaymer | Posted 1:12am 29. August 2010 Server Time |

http://www.bestsleepingpill.net/ ordering ambien online mghyrt http://www.viagra-advice.com/ viagra sale =-DDD http://www.skincaremedication.net/ accutane online pharmacy 3914 http://www.phentermine-hcl.org/ phentermine =-)))
dlrudisha | Posted 11:59pm 31. August 2010 Server Time |

http://www.thai-rama-az.com/lifeinsurance.html life insurance quotes 8)))


Reply to Post MS Access open Word



Back to Forum Page