473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to open a word document and enter data from access

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
1 2061
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

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

Similar topics

0
by: Unigroup of New York | last post by:
Content-Type: multipart/mixed; boundary="------------C465DF38DCB38DD2AF7117E0" Lines: 327 Date: Tue, 15 Feb 2005 23:36:38 -0500 NNTP-Posting-Host: 24.46.113.251 X-Complaints-To: abuse@cv.net...
7
by: Kenneth_J | last post by:
Hey everyone, I just started doin some work with access and vba, and don't know much about it yet...any help would be much appreciated. My goal is to create a form in word that can be filled...
10
by: Neil | last post by:
An article at http://news.com.com/2100-1012-991694.html?tag=fd_top states: "XML would allow easier interchange of data generated in Office documents with back-end systems or existing Web...
3
by: Andy Davis | last post by:
How do i or can I open a word document directly from Access? I would like to be able for the user to click a button on my form to open a word document and then also run a macro in Word. Thanks...
1
by: ashkash | last post by:
I have an access database which takes information from a user and then uses the mail merge functionality to merge the data into a word document. I have a lot of subforms in the access database which...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
6
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. ...
2
by: hharry | last post by:
Hello All, Does anyone know of a method to automatically detect if a file is corrupted ? Due to a failed backup process a number of files were corrupted. The files are mostly .xls, .doc, .pdf....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.