By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

Print form in MS Access to new MS Word doc with the name being based off the first co

P: 1
I am trying to create a button that will take data pulled up on a form in MS Access and use it to create a MS Word document with a name based off of the combo box. I have a database that data is pulled from based off of a combo box and populates the other fields but I want to use the name in the combo box to take all the fields and put it into a MS Word doc.




Expand|Select|Wrap|Line Numbers
  1. Public Sub msword_Click()
  2.     Dim wd As Object
  3.     Dim wdDoc As Object
  4.     wd = New word.Application
  5.     wd = CreateObject("\\gpdc\Company Shared\Molding Line" & Me.GPCNum & ".dotx") 'wd.Documents.Add("\\gpdc\Company Shared\Molding Line" & Me.GPCNum & ".dotx")  'Add document to Word
  6.     wd.Visible = True
  7.     wdDoc = word.Documents.Add
  8.     With wdDoc
  9.         .FormFields("GPC Number").Result = GPCNum.Text
  10.         .FormFields("Description").Result = txtDescription.Text
  11.         .FormFields("Material").Result = txtMaterial.Text
  12.         .FormFields("Cavities").Result = txtCavities.Text
  13.         .FormFields("Hot Cycle").Result = txtHot.Text
  14.         .FormFields("Cold Cycle").Result = txtCold.Text
  15.         .FormFields("Mold").Result = txtMold.Text
  16.         .FormFields("Demold").Result = txtDemold.Text
  17.         .FormFields("Special").Result = txtSpecial.Text
  18.     End With
  19.     'wdDoc.PrintPreview() 'Opens print Preview Window
  20.     wdDoc.SaveAs ("\\gpdc\Company Shared\Molding Line\" & Me.GPCNum & ".dotx") 'Saves the Document
  21.     'wd.Application.Quit()
  22.     'Closing Word Application
  23.     wd = Nothing 'Releasing References to Variable
  24.  
  25. End Sub
4 Weeks Ago #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.