Database List Box Control Problem! 
Author Message
 Database List Box Control Problem!

You could do something like this...

'Set up a recordset containing the data from your table

'Fill the listbox with the names from the recordset
With rs
    .MoveFirst
    Do Until .EOF
        listbox.Add rs![Last Name] & "," & rs![First Name]
        .MoveNext
    Loop
End With

Then when they click on the name in the list box, you could set up a
recordset using a SQL statement pulling the info for that customer, or you
could have an existing recordset with the data for all customers and when
they click on a name, search based on the customer they clicked on.
(.Find,.Filter, etc.)

You will find that setting up a new recordset based on the customer using a
SQL statement will be much faster, but the .Find method and .Filter property
are easier to use. It's up to you.

HTH

Brian


Quote:
> Hi,

> I need to fill a list box with a list of clients, starting with the last
> name first then the first name.  All the data comes from an Access
database.
> The first and last names are stored in separate fields in a table, but i
> need them listed as follows:

> LastName, FirstName

> Then i need to be able to click on a name and have information come up.
An
> example of what i need is in the picture i am attaching.
> Any help would be great!!!

> Eric



Tue, 12 Oct 2004 23:28:04 GMT  
 Database List Box Control Problem!
Another, much easier variation on what Brian suggested is to create a query
in access with only the primary key
and a derived field.  the example below is for a derived field named
searchname.

SearchName: [LastName] & ", " & [FirstName]

Call the access query to fill the list box

the code to file the list box is very similar toBrians except add one more
line right after the "listbox.add" line

listbox.ItemData(listbox.NewIndex) = rs![keyfield]

this will associate the primary key in the database with the record in the
listbox.  then when you select one of the
records in the listbox, pass the value of the Listbox.Itemdata to a Select
statement where clause.

"Select * from Table where KeyField = " &
ListBox.ItemData(Listbox.SelectedIndex)

with this code you will always retrieve the correct record with a minimum of
code or hassel.

Hope that helps

Kevin


Quote:
> You could do something like this...

> 'Set up a recordset containing the data from your table

> 'Fill the listbox with the names from the recordset
> With rs
>     .MoveFirst
>     Do Until .EOF
>         listbox.Add rs![Last Name] & "," & rs![First Name]
>         .MoveNext
>     Loop
> End With

> Then when they click on the name in the list box, you could set up a
> recordset using a SQL statement pulling the info for that customer, or you
> could have an existing recordset with the data for all customers and when
> they click on a name, search based on the customer they clicked on.
> (.Find,.Filter, etc.)

> You will find that setting up a new recordset based on the customer using
a
> SQL statement will be much faster, but the .Find method and .Filter
property
> are easier to use. It's up to you.

> HTH

> Brian



> > Hi,

> > I need to fill a list box with a list of clients, starting with the last
> > name first then the first name.  All the data comes from an Access
> database.
> > The first and last names are stored in separate fields in a table, but i
> > need them listed as follows:

> > LastName, FirstName

> > Then i need to be able to click on a name and have information come up.
> An
> > example of what i need is in the picture i am attaching.
> > Any help would be great!!!

> > Eric



Sun, 31 Oct 2004 13:13:05 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Database Control for List Box?

2. List Records of a Database in a Standard List Box

3. List Records of Database in List Box

4. VB5/6 List Box Control Problem

5. List Box control problem

6. Problems with Pattern property of file list box control

7. MatchEntry property problem on combo box and list box

8. List Box with Check Box Controls Inside

9. How to list macro names in a combo box or a list box

10. Help wanted with file list boxes and list boxes

11. VB List Box Versus Access List Box

12. Q: List Box to List Box Code

 

 
Powered by phpBB® Forum Software