Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I........?? 2

Status
Not open for further replies.

CIMTEET

Programmer
Jun 25, 2001
182
0
0
US
How do I return all records in a table based on one field. Ex. Return all records that have someone who was has red hair. Assuming their is a hair color field. (I know, stupid example but I hope it gets the point across) I am using an ADO control to connect to the database. Please Help!!

Greg
 
This is a broad example that will hopefully get you started in the right direction. It's looking at a SQL Server database. To connect to Access you would change the connection string. Also to do this you must reference Microsoft ActiveX Data Objects Library.


Public Const ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;" _
& "Initial Catalog=PeopleData;Data Source=DOR-SRVR-DATA"


dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cn = New ADODB.Connection
cn.Open ConnectionString
Set rs = New ADODB.Recordset
rs.Open "Select LastName From Employee Where HairColor = 'Red'", cn, adOpenDynamic, adLockOptimistic
if not rs.eof
me.txtHairColor = rs.fields("HairColor")
endif
rs.close
set rs = nothing
cn.close
set cn= nothing

I hope this gets you started.
RKA:)

 
....continuing the above answer, if you want to process each record in any way , right after rs.open....
you can say
rs.movefirst
for intctr = 1 to rs.recordcount
'get the fields of firstrecrd say last name
strtemp = rs!lastname
--------
-----
rs.movenext
next intctr

I think that's all your requirement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top