using query in form

R

rathika

hi

i have a query like

select ename,sal,desig from emp
where empno=forms!textboxvalue


now how do i use this query in the form to get these
3 field values(ename,sal,desig) in 3 different text boxes
of the form

pls. help
rathika
 
J

JohnFol

How are you running the query? Is it the recordsource of a form or is this
in code.?
 
M

Mercy

You might want to do this through ADO ... but it should be
similiar to DAO ... just different syntax.

Assuming that the values you want can be derived from your
textbox value ... which is already on the form.

I would create a subprocedure for the after update event
on the "textboxvalue" in VB

The subprocedure would look something like this:

Dim db As Database
Dim rec As Recordset
Dim strQry as String

strQry = "YourQry" ' Create qry

Set db = CurrentDb() ' set db to Current Database
Set rec = db.OpenRecordset( strQry) ' Open a recordset
based on the defined qry

Me!field= rec!field ' Set the field values


Instead of creating a String you COULD just put in the Qry
name ie: Set rec = db.OpenRecordset( QryName)

But because your "textboxvalue" is probably going to
change ... I would set the String equal to:
"SELECT ename, sal, desig FROM emp WHERE empno = " & forms!
textboxvalue

The "&" is a way to concatenate strings :) (It took me 3
hours to figure the "&" out :p)


I hope that helps... and if anyone thinks my approach
isn't the best one ... please feel free to correct :)

-Mercy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top