Beginner: Populating text box by selecting from list box 
Author Message
 Beginner: Populating text box by selecting from list box

Hello,

I am trying to populate text fields by selecting information from a
listbox.

I would like the listbox populated with a name(sorted ascending) derived
from a field in a table. Next I would like to populate some text boxes(3
at this stage) by selecting a name from the listbox. By selecting the name
this would as an action populate the text box with the related information.

Can you show me how to populate the text fields on the form from the same
table as the name field and also from other tables which are related using
referential integrity.

I would like to use ADO to make the connection.

I used MsAccess to make up the database. But would like to use VB6 as  a
front end interface.

If you need any more information let me know.
Any Help greatly appreciated

--
Posted via CNET Help.com
http://www.***.com/



Sun, 22 Dec 2002 03:00:00 GMT
 Beginner: Populating text box by selecting from list box

Quote:

> I am trying to populate text fields by selecting information from a
> listbox.

> I would like the listbox populated with a name(sorted ascending) derived
> from a field in a table. Next I would like to populate some text boxes(3
> at this stage) by selecting a name from the listbox. By selecting the name
> this would as an action populate the text box with the related information.

> Can you show me how to populate the text fields on the form from the same
> table as the name field and also from other tables which are related using
> referential integrity.

> I would like to use ADO to make the connection.
> I used MsAccess to make up the database. But would like to use VB6 as  a
> front end interface.

G'day Ken.
  There are many ways to crack this nut so the quick answer is, "it
depends..."  For example, after you fill the ListBox from the recordset
(the records from Name field in your table, right?), do you leave the
recordset open or did you Close it?  There are arguments to be made for
either approach, but which do you wanna do?
  Are you fairly familiar with writing SQL statements, especially for
joining tables?
  Is the name you display in the ListBox unique for each record (i.e.,
if you display a person's last name like 'Smith', there might be many
'Smiths' in the table so how would VB know which one the user intends to
select to fill the TextBoxes)?
  Assuming the ListBox (named lstNames) displays a unique name, in the
lstNames_Click event you could open a new recordset (named rsMoreInfo)
off your ADO connection (named cnnToDb, declared so as to be available
to lstNames_Click and already Open).  In the example below, substitute
your real field names in place of my 4 'fld...' names; also substitute
real name of YourTable;  my example TextBoxes are named per the VB
default.

Dim rsMoreInfo As ADODB.Recordset
Dim strSQL AS String

'SQL to select some other fields for Name selected in lstNames
strSQL = "SELECT fldAddress, fldCity, fldPhone FROM YourTable " _
       & "WHERE fldName = '" & lstNames.Text & "'"

'get recordset and fill Textboxes, then get rid of recordset
Set rsMoreInfo = New ADODB.Recordset
rsMoreInfo.Open strSQL, cnnToDb, adOpenStatic, adLockReadOnly
With rsMoreInfo
   Text1.Text = .Fields("fldAddress").Value
   Text2.Text = .Fields("fldCity").Value
   Text3.Text = .Fields("fldPhone").Value
   .Close
End With
Set rsMoreInfo = Nothing

  So that's *one* way - not that I'm saying it's the *right* way for
your situaion.  Now if you want an example for joining info from another
table, I really think it's better if you'd post some real table/field
names, including the key field for the join.
  Hope this is of some use to you
--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"
 ((("What's so funny 'bout peace, love & understanding?" - Nick Lowe)))



Sun, 22 Dec 2002 03:00:00 GMT
 Beginner: Populating text box by selecting from list box
Hello once again Jim

Your help, as usual, has solved my problem. I am a beginner at this and
hope to improve, and I am sure I will. Especially when there are people
such as yourself who are willing to put aside precious time to solve the
problems of others.

Somehow thank you seems inadequate but at this time thats all I have.

Thanks Jim

Kind regards
Ken

Quote:


> > I am trying to populate text fields by selecting information from a
> > listbox.

> > I would like the listbox populated with a name(sorted ascending)
derived
> > from a field in a table. Next I would like to populate some text boxes
(3
> > at this stage) by selecting a name from the listbox. By selecting the
name
> > this would as an action populate the text box with the related
information.

> > Can you show me how to populate the text fields on the form from the
same
> > table as the name field and also from other tables which are related
using
> > referential integrity.

> > I would like to use ADO to make the connection.
> > I used MsAccess to make up the database. But would like to use VB6 as  
a
> > front end interface.

> G'day Ken.
>   There are many ways to crack this nut so the quick answer is, "it
> depends..."  For example, after you fill the ListBox from the recordset
> (the records from Name field in your table, right?), do you leave the
> recordset open or did you Close it?  There are arguments to be made for
> either approach, but which do you wanna do?
>   Are you fairly familiar with writing SQL statements, especially for
> joining tables?
>   Is the name you display in the ListBox unique for each record (i.e.,
> if you display a person's last name like 'Smith', there might be many
> 'Smiths' in the table so how would VB know which one the user intends to
> select to fill the TextBoxes)?
>   Assuming the ListBox (named lstNames) displays a unique name, in the
> lstNames_Click event you could open a new recordset (named rsMoreInfo)
> off your ADO connection (named cnnToDb, declared so as to be available
> to lstNames_Click and already Open).  In the example below, substitute
> your real field names in place of my 4 'fld...' names; also substitute
> real name of YourTable;  my example TextBoxes are named per the VB
> default.

> Dim rsMoreInfo As ADODB.Recordset
> Dim strSQL AS String

> 'SQL to select some other fields for Name selected in lstNames
> strSQL = "SELECT fldAddress, fldCity, fldPhone FROM YourTable " _
>        & "WHERE fldName = '" & lstNames.Text & "'"

> 'get recordset and fill Textboxes, then get rid of recordset
> Set rsMoreInfo = New ADODB.Recordset
> rsMoreInfo.Open strSQL, cnnToDb, adOpenStatic, adLockReadOnly
> With rsMoreInfo
>    Text1.Text = .Fields("fldAddress").Value
>    Text2.Text = .Fields("fldCity").Value
>    Text3.Text = .Fields("fldPhone").Value
>    .Close
> End With
> Set rsMoreInfo = Nothing

>   So that's *one* way - not that I'm saying it's the *right* way for
> your situaion.  Now if you want an example for joining info from another
> table, I really think it's better if you'd post some real table/field
> names, including the key field for the join.
>   Hope this is of some use to you
> --
> Jim in Cleveland
> If you're writing to me, in my address
> change "REAL_Address.see.below" to "worldnet.att.net"
>  ((("What's so funny 'bout peace, love & understanding?" - Nick Lowe)))

--
Posted via CNET Help.com
http://www.help.com/


Mon, 23 Dec 2002 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Toggling Between List Boxes at the Same Location and Selecting Records in Each List Box

2. populate list box with text file

3. ADO List box and Text boxes

4. List box search based on text box entry...

5. Update Text Box from List Box

6. Problems making a automatic text box when selecting in a combo box

7. list box 2 based on list box 1

8. Populating a combo box from another combo box

9. Populate a combo box from another combo box selection

10. Updating a combo box list W/limit to list selected

11. Help the New Guy populate a LIST box

12. Populate a list combo box


 
Powered by phpBB® Forum Software