Need HELP Importing Access List Box data to Word document 
Author Message
 Need HELP Importing Access List Box data to Word document

Bill,

If I'm understanding you correctly,  you want to take the data in the list
boxes and 'dump' it out to a Word document.  Here's a few code snipets to
help:

First you have to create  and instance of Word:

---------------------------------
Dim oWord as object
Set oWord = CreateObject("Word.Application.8")    'assuming Word 97
---------------------------------

Once you've created this object, you can use the object browser (F2) from
within Access to navigate down the object hierarchy to create the output you
want.  For example:

----------------------------
oWord.Documents.Open "C:\mydocument"        'open the document
oWord.ActiveDocument.Bookmarks("ClientName").Select        'go to the
bookmark where you want to insert the content oWord.Selection.InsertAfter
Forms!MyForm!MyListBox    'puts in the value from your list box into the
selected Word bookmark
--------------------------

As far as looping through the contents of the list box, there are several
things you can try.  As as side note, if you have a query that is the row
source for the list box, you can just as easily loop through all the records
using DAO or ADO, for example, and dump those out to Word:

-----------------------------------
Dim rst as Recordset
Dim db as Database

set db=Currentdb()
set rst=db.OpenRecordset("MyQuery",dbOpenDynaset)

rst.movefirst    'goto the beginning of recordset
Do Until rst.EOF    'loop through each record until at the end
    oWord.selection.insertafter rst!ClientName        'insert client name
    oWord.selection.InsertParagraphAfter                'then a paragraph
break
    rst.movenext
'go to the next record
Loop
------------------------------------

However a much easier way is to is use the InsertDatabase method of Word's
range object (refer to the object browser' help on this).  Essentially you
pick a starting poing and can dump out the whole query to a Word table with
one line of code!

Another way is to loop through each selected record in the list box with a
For...Next construction:

---------------------------------
Dim ctl as Control
Dim intCurrentRow as Integer

set ctl = Forms!MyForm!MyListBox

For intCurrentRow = 0 To ctl.Listcount - 1  ' 0 based list of all items in
the box
    If ctl.Selected(intCurrentRow) Then
        'Dump into Word or do something with it
    End If
Next intCurrentRow
---------------------------------

Hope that helps.

Jeff

Quote:

>Hi everyone.

>I have successfully populated several list boxes with data from option
>box
>choices via queries in Access.

>Now I need to get that information residing in the list box(es) to a
>Word
>Document.  Namely an Insurance policy.  Otherwise I would use the report

>generator.  30 pages is just too much.

>It appears I will need to write some VBA code to do this from the Word
>side as a
>list or text box function.

>Does anyone know how to do this with VBA code?  I am still new at Access
>and VBA......It would advance my project considerably!!!

>I will be getting VB6 next week, but I want to get it done in VBA first.

>Then migrate the project to VB when it is finished.

>Thank you for any suggestions!!!!!  Please feel free to email me
>directly as well.

>Bill Fulbright
>2100 Solutions, Inc.
>Product Development, IVR/VRU, Automated Call Centers - Design & Startup,

>Y2K, Testing

> http://www.*-*-*.com/
>904-448-6300
>ICQ# 2251620

>--
>Bill Fulbright
>2100 Solutions, Inc.
>Product Development, IVR/VRU, Automated Call Centers - Design & Startup,

>Y2K, Testing

> http://www.*-*-*.com/
>904-448-6300
>ICQ# 2251620



Mon, 15 Oct 2001 03:00:00 GMT  
 Need HELP Importing Access List Box data to Word document
Hi everyone.

I have successfully populated several list boxes with data from option
box
choices via queries in Access.

Now I need to get that information residing in the list box(es) to a
Word
Document.  Namely an Insurance policy.  Otherwise I would use the report

generator.  30 pages is just too much.

It appears I will need to write some VBA code to do this from the Word
side as a
list or text box function.

Does anyone know how to do this with VBA code?  I am still new at Access
and VBA......It would advance my project considerably!!!

I will be getting VB6 next week, but I want to get it done in VBA first.

Then migrate the project to VB when it is finished.

Thank you for any suggestions!!!!!  Please feel free to email me
directly as well.

Bill Fulbright
2100 Solutions, Inc.
Product Development, IVR/VRU, Automated Call Centers - Design & Startup,

Y2K, Testing

http://members.tripod.com/IVR download resume from website
904-448-6300
ICQ# 2251620

--
Bill Fulbright
2100 Solutions, Inc.
Product Development, IVR/VRU, Automated Call Centers - Design & Startup,

Y2K, Testing

http://members.tripod.com/IVR download resume from website
904-448-6300
ICQ# 2251620



Tue, 16 Oct 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. help!need help abt list box and access

2. List box within a word document

3. List Box within a word document

4. please help - need help on identifying last word in document

5. VB List Box Versus Access List Box

6. Heeeeelp...I need to import data from Excel to a tabel in Access

7. MCP Needs help: Trying to list Imports/Exports table from Visual Basic

8. Help: best way to import data from Word forms

9. merging data from a secured Access database into a Word document

10. Using Access Database - need to put a word document in

11. Help wanted with file list boxes and list boxes

12. Need access to a word list in VB...

 

 
Powered by phpBB® Forum Software