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

Type in a KeyID... Show that KeyID ROW

Status
Not open for further replies.

Mudassar

Programmer
Oct 3, 2000
110
AU

I have a textbox I made.
If a user types in a number, eg 2,
then another window pops up and shows the number 2 details.

How would I do that by writing it in code?
OR is there a special Wizard?


my Form looks like this:
________________________
|User___________________X|
| |
| Welcome, type in a ID |
| [2 ] {OK} |
|________________________|

My tabel kinda looks like this:

KEYID Name Age
1 Alex 43
2 Joe 23 <--- say if user wants this
3 Sam 56
4 Moo 02
5 Mark 32


Result Window:
_______________
|______________X|
| Results: |
| |
|KEYID: 2 |
|NAME: JOE |
|AGE: 23 |
|_______________|

Note: The results are shown in a label or a textbox.

-----------------
MK

Everybody should use AntiVirus! Are you protected now?
 
Here is the way that I would do this. Although I think that there is most likly a better way to do it. In your button handler put the following code. Make sure you change tablename to your table name and ID to your text box
Code:
on error goto Err
    
    /this set of code creates a query in memory
    Dim db As Database
    Dim qry As QueryDef
    Dim rst As Recordset
    Set db = CurrentDb
    Set qry = db.CreateQueryDef(&quot;&quot;, &quot;SELECT * FROM tableName WHERE = KEYID = &quot; & me.ID)
    Set rst = qry.OpenRecordset()

    'tests to make sure that the query got some data    
    if rst.eof = false then
         'creates a message box with your data in it
         msgbox &quot;Results:&quot; & vbcrlf & vbcrlf & &quot;KEYID: &quot; & rst!KEYID & vbcrlf & &quot;Name: &quot; & rst!Name & vbcrlf & &quot;Age: &quot; rst!Age

'make sure you do this or you will have a memory leak
set rst = nothing
exit sub
Err:
msgbox err.description

If you want to put the data in a form with that you made, open the form and set the boxes that you want equal to the recordset fields. (myTextBox = rst!KEYID) The hardest questions always have the easiest answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top