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

User input used to query 1

Status
Not open for further replies.

DreadPirate

Technical User
Sep 3, 2001
8
US
Hi all. Sorry, another newbie here with a question that is sure to make you laugh. I apologize in advance for my simple mind.

Here's the issue; I have a table in Access. I'm trying to use a VB program to query that table and bring up info from several fields. The user types in a CityID (the key field in the table) and a few other fields pop up in a new form. Simple, I'm sure, but infuriating. How do you pass the variable from the User input to the data call? Here's the code I've been trying. I'm sure the reason it doesn't work is due to the ridiculous place I stuffed the variable "IDinput", but I don't know how else to do it. Please, Please help.

Private Sub cmdTest_Click()
Dim IDinput
IDinput = txtIDEnter.Text 'this is the user input box

Data1.Recordset.FindFirst "CityID = '(IDinput)'"

txtTest.Text = Data1.Recordset.Fields("Region").Value

End Sub
 
no problem.dont feel like that.cheer up.
try this
if cityid is a string type try this command
-------
Data1.Recordset.FindFirst "CityID ='" & IDinput &"'"
-------
otherwise cityid is an integer type
then
------
Data1.Recordset.FindFirst "CityID =" & int(IDinput)
---------

all the best
raghu

 
Thanks a bunch. That answers my Variable-placement dilemna. Unfortunately, The process is still not working properly; When I test it, it always brings up the Region Field of London. Not that I have anything against London, but Even if I type in the CityID for Madrid, It still checks the Region field for London. Could it be the display line that is at fault?

txtTest.Text = Data1.Recordset.Fields("City").Value

Again, thanks for your prompt and courteous attention.

{R}
 
try it simply like
txtTest.Text = Data1.Recordset("City")
other wise check the field name is spelled correctly

raghu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top