How to read fields into list boxes? 
Author Message
 How to read fields into list boxes?


writes:

Quote:
> Could someone help me figure out how to:

> 1) query Access for records that match certain criteria
> 2) Read the first field of those matching records into a list box?

The first part was answered by someone else, for the second try:

while not dataobject.eof
        List1.additem dataobject("fieldname")
        dataobject.movenext
wend
dataobject.close

 replace dataobject with the name of your data object
 if you are using a data control use the syntax:
dataobject.recordset<command>

hope this helps

---------------------------------------------------
                C:\>Finished formatting drive C:
                C:\>Format Another y/n?
Grant



Wed, 17 Sep 1997 03:00:00 GMT  
 How to read fields into list boxes?

Quote:

>  Hello VB gurus:

>  Could someone help me figure out how to:

>  1) query Access for records that match certain criteria
>  2) Read the first field of those matching records into a list box?

>  I know how to query Access for a single record, and get the data from that
>  record, but how do you collect the list of records that match the
>  specified criteria?

You would use either the dynaset method or the data control.  IMHO, I would
opt for the dynaset method.  With the dynaset or the data control method, you
would have to pass a SQL statement that will select the records from the database/
table based on the criteria you've set.  For example, if you want to retrieve all the
records (info on names) that has lastname equal to SMITH you would do something
like this

Set db=Opendatabase("databasename or path",,,connect method) //please refer to OpenDatabase in
                                                        the help file for all parameters

Set ds=db.CreateDynaset("SELECT * FROM NAMES WHERE LASTNAME='SMITH'")

While NOT ds.eof
        listbox.additem ds.Fields("LastName or other fieldnames")
        ds.MoveNext
Wend

that's it,
andrew



Wed, 17 Sep 1997 03:00:00 GMT  
 How to read fields into list boxes?
: Hello VB gurus:

: Could someone help me figure out how to:

: 1) query Access for records that match certain criteria
: 2) Read the first field of those matching records into a list box?

Dim Requested_Records As Dynaset
SQLString = "Select * From [" & Table_Name & "] Where [" & Field & "] = ""A"" "
Set Requested_Records = DB.CreateDynaset(SQLString, DB_READONLY)

: I know how to query Access for a single record, and get the data from that
: record, but how do you collect the list of records that match the
: specified criteria?

: Any advice or suggestions would be greatly appreciated.

: Thanks in advance -

: Roy Strauss
: (Trying to learn VB instead of sleeping)



Wed, 17 Sep 1997 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to read fields into list boxes?

2. Reading file name from text box and/or File List Box

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

4. Help wanted with file list boxes and list boxes

5. VB List Box Versus Access List Box

6. Q: List Box to List Box Code

7. List box within List box

8. List box within List box

9. List box within List box

10. Read and list mpp files in a dialogue box with VBA

11. How to read file contents into list box.

12. How to make a list box read only

 

 
Powered by phpBB® Forum Software