List boxes and ADOC Controls

Posted on 2003-02-21
Medium Priority
Last Modified: 2010-04-17
What is the code to for a list box, that when an item is selected it will display the apporiate information that coincides with that item.  There is a database connected to the form using an ADOC control.  For example lets say there is a list box that contains the names of people and when one of the names is selected in the list another form will open to display that person's infomation.
Question by:bikerChic
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

JoaTex earned 150 total points
ID: 7996744
Hi There

Let's see if it's this that you Want

Suposing that the 3 First Fields on your data base are:
Client, Name, Adress

Create a listBox that lists:

This listIndex should be the same as your FieldsIndex database.

Now you must index the record to those fields EX:
Data1.recordset.absolute position=10

now on your sub List1Click()you must have:
Text1.text = list1.list(list1.listindex)

When you select name on listbox Text1 wil be the name of your database.

hope this suites you
Sorry about my english.

Author Comment

ID: 7997120
Thanks I will try it I am not fimilar with ADOC I only know DAO.

Expert Comment

ID: 7998193
if u want to get info from any table through listbox
just suppose u have only two fields in ur table place two text boxes and a command button and a datalistbox
it normaly not appears on the tool box u have to add it from components by right clicking the
 toolbox/components/microsoft DataListContols(OLEDB)6.0
place it on the pro ject and copy this code in code window

' the code starts here

Option Explicit
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub Command1_Click()
Dim a As String
a = "select * from pw1 where u_name='" & DataList1.Text & "'"           ' run  this query just suppose ur table name is pw1
Set rs = db.Execute(a)

MsgBox rs(0)
 Text1.Text = rs(0)
Text2.Text = rs(1)
End Sub

Private Sub Form_Load()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset

db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\hello\pw.mdb"   and ur database path is like that
     '     ^                    '     ^          
     '     |                    '     |
     'and ur database type'          'there u have to
' write down the path of ur data base'                                        

End Sub
'the code ends here


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Introduction to Processes

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question