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

How to open a word document and enter data from access

P: 1
I'm trying to open a word document from access and enter some data from my access form into the document.

I've used this code:

Dim objWord As Object
Dim objDocument As Word.Document

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDocument = objWord.Documents.Add

This opens a new word document. However, I can't work out how to go from here to entering data automatically. Can anyone help?
Jun 7 '07 #1
Share this Question
Share on Google+
1 Reply


theaybaras
P: 52
I'm trying to open a word document from access and enter some data from my access form into the document. ...
Can anyone help?
Hi icthus123...
I am pretty new at this, and haven't taken text from Access to Word before. So I played around a little bit. Assuming a single text field called txtMemo that we want to import into a new Word Document. the code I generated to take that data into MSWORD in a new document is as follows.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdWord_Click()
  2. On Error GoTo Err_cmdWord_Click
  3.  
  4.     Dim objWord As Object
  5.     Dim objPrintout As String
  6.  
  7.     objPrintout = Me.txtMemo.Value
  8.     Set objWord = CreateObject("Word.Application")
  9.           objWord.Visible = True
  10.           objWord.Documents.Add
  11.           objWord.Selection.TypeText objPrintout
  12.  
  13. Exit_cmdWord_Click:
  14.     Exit Sub
  15.  
  16. Err_cmdWord_Click:
  17.     MsgBox Err.Description
  18.     Resume Exit_cmdWord_Click
  19.  
  20. End Sub
This worked for me for one text box. I haven't played with how to loop through to get the data from multiple places, but that part should be fairly simple if you just change the variable on each loop to take the data from multiple fields. You can concatenate as normal and even set formatting options, and the syntax for those formatting options should be readily available online.

Let me know how it goes! If you can't get it to work, let me know and we'll see what we can figure out :)

theAybaras
Jun 8 '07 #2

Post your reply

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