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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXTRACTING DATA FROM A TABLE

Status
Not open for further replies.

gjflash

Technical User
Nov 9, 2001
4
US
I am using Visual Basic 6.0
I created a data base in Visual Basic (MS Access 7 type)
I called the data base TPDB. Mdb
I called the table TP
I created three fields in the table
Field 1 Called Temp
Field 2 Called P1
Field 3 Called P2

--------------------Temp-----P1------P2

Record 1---------1---------- 6-------- 9
Record 2-------- 2-----------7--------10
Record 3---------3---------- 8--------11

In The Form
I created a text box 1 that I want to enter a number that I know is in the P1
Field
I created a text box 2 that I want the associated number from the Temp Field
to be recorded in.

I set the Data control Properties to read
Database Name =TPDB.Mdb
Recordset Type =Table
RecordSet Source= TP

I created a button and tried to write code to do the following.
Find Record where the P1 Field = Text1.Text (Example 7)
Place Number from Temp Field of same record in Text2.Text (Example 2)

Simple HUH
Not for this Novice

Please write simple code so I get the drift.
 
Here's how I would do it:
If you put the following code to occur when the OnClick property of your button is activated, then it should be ok.
I haven't checked it though, so there could be the odd typo, but let me know if it works ok.

RFletch

dim db as dao.database
dim rcd as dao.recordset
dim found as boolean
set db = current db
set rcd = db.openrecordset("TP")
found = false
rcd.movefirst
do until found = true or rcd.eof
if rcd![p1] = Me![Text1] Then
found = true
Me![text2] = rcd![temp]
else
rcd.movenext
end if
loop




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top