Re: Populating a list box from a database
From: Mara M. Smith (Smith_at_discussions.microsoft.com)
Date: 11/29/04
- Next message: btmcfadden_at_msn.com: "Re: method not known or available"
- Previous message: Helmut Weber: "Re: method not known or available"
- Next in thread: Alex Ivanov: "Re: Populating a list box from a database"
- Reply: Alex Ivanov: "Re: Populating a list box from a database"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 29 Nov 2004 10:09:48 -0800
Doug,
I like your solution below. I tried it and it worked. I was wondering if
you or anyone else could provide a solution to one of my problems related to
this. I will be using the code you used when the form initializes but I used
my access database to populate a 'combo box'.
After making a selection in the 'combo box', if I click 'ok' on my user
form, I would like to pull a specific field(for example, the phone number of
the person I selected in the combo box) from that same database that
populated the 'combo box'. I would then want to insert that phone number in
a 'bookmark' named 'Phone_Number' in the Word file I am using.
How can I do this?
Thanks,
MM
"Doug Robbins" wrote:
> Use the following method (You need to set a reference to the DAO object
> library)
>
> 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
>
>
> --
> 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
> "Dingbat" <Dingbat@discussions.microsoft.com> wrote in message
> news:187666DA-38BC-49B5-AA40-91C406A04B61@microsoft.com...
> > Can I populate a list box in word from values within an access database?
> >
> > I am using Microsoft Word 2002/Access 2002.
> >
> > I want to be able to dynamically build the values within the list box from
> > the result of a query within access
>
>
>
- Next message: btmcfadden_at_msn.com: "Re: method not known or available"
- Previous message: Helmut Weber: "Re: method not known or available"
- Next in thread: Alex Ivanov: "Re: Populating a list box from a database"
- Reply: Alex Ivanov: "Re: Populating a list box from a database"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|