Reply
 
Thread Tools Display Modes
  #1   Report Post  
Tlar
 
Posts: n/a
Default import data into word from excel or access

I have a similar issue. Doug I used your recommended code and it works
however it only takes one item from the listbox in my user form and inserts
it into my word textfield. HOw do I get all say 6 items listed in the
listbox of my user form to be inserted into a word doc form field? Can I go
userform listbox to word textfield?
thanks for all your great help.
Tlar

"Doug Robbins" wrote:

Use a userform in the template and use the following code in the initialize
event of the user form to populate a listbox on the userform with the names
and addresses of the individuals from your database:

Private Sub UserForm_Initialize()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
' Open the database
Set db = OpenDatabase("D:\Access\ResidencesXP.mdb")
' Retrieve the recordset
Set rs = db.OpenRecordset("SELECT * FROM Owners")
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
' Set the number of Columns = number of Fields in recordset
ListBox1.ColumnCount = rs.Fields.Count
' Load the ListBox with the retrieved records
ListBox1.Column = rs.GetRows(NoOfRecords)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing

End Sub

The following code in the click event of a command button on the user form
will get the information from the record that is selected in the listbox and
insert it into the document at the location identified by a bookmark that is
inserted into the template:

Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.Insert After Addressee
UserForm2.Hide
End Sub

To see how to get started with a userform, see the article "How to create a
Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
"David" wrote in message
...
Hi there,

I want to be able to automatically fill in address information in a
template
when I type in the name of a person. Can someone help explain how I do
this?
A marco or something maybe? The info will be stored in excel spreadsheet
or
access....

thanks!!!!!

david




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I divide a page into three sections? Bonnie Microsoft Word Help 3 May 8th 23 02:47 AM
formatting links from excel into word (extra line feeds) JGT Microsoft Word Help 1 December 9th 04 12:01 PM
how can i import a tabbed word document into excel? jared Microsoft Word Help 1 December 2nd 04 01:35 AM
How do I insert Excel data into a Word Letter? DirkWestphal Microsoft Word Help 1 December 1st 04 10:09 PM
How do I convert a cd in word perfect to microsoft word greylady Microsoft Word Help 1 November 23rd 04 08:03 PM


All times are GMT +1. The time now is 12:55 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"