Hi Graham, thank you for the link.
However, the question I posted on 15-9-09 (which, nobody wanted to answer),
lists the code that I had worked out for myself, as taken (verbatim) from
greg's tutorial, named "Access Example 2".
I could not get "Access Example 1" to work for me, but the second (#2) works
perfectly, except that I can get only "one" field to print to the report (the
"first" field...), It contains a list of last names.
The combobox fills perfectly with all the fields, and I can choose a row
complete with all the listings, but only the 1st field prints to the report.
The code I am using is within the: Private Sub
UserForm_Initialize()/end sub statement
(enabled library is: “Microsoft DAO 3.6 Object Libraryâ€)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
'Open the database to retrieve data
Set db = OpenDatabase("C:\Databases\Docs.mdb")
'Define the first recordset
Set rs = db.OpenRecordset("SELECT * FROM Docs ORDER BY [Last]")
'Determine the number of records in the recordset
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
'Set the number of ListBox columns = number of fields in the recordset
ComboBoxDocs.ColumnCount = rs.Fields.Count
'Load the ListBox with the retrieved records
ComboBoxDocs.Column = rs.GetRows(NoOfRecords)
'Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
The data then should transfer to the report via a simple bookmark after the:
Private Sub cmdOK_Click()
user form section, the bookmark is called:
ActiveDocument.Bookmarks("AllDocs").Range.Text = ComboBoxDocs.Text
The codes will only transfer a single name (from the first field of the
database table). I'm sure I am (again) just missing something simple in all
this, but any advice is greatly appreciated.
Graham Mayor said:
See
http://gregmaxey.mvps.org/Populate_UserForm_ListBox.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>