inputbox question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

can anyone tell me how to use an inputbox for searching info in a database?
for example, user wants to search all employees living in new york. when he
clicks the command button, an inputbox will appear asking him to enter his
chosen city. what command can i use to do that? i know it may be simple for
some people but i'm really having a hard time remembering what code to use.
it's been a while since the last time i used access. thanks.
 
thanks. i got the code for inputbox. but my problem is how to search for data
in a table using the info entered in the input box. i've tried the select
query equation but it's not working. more help please... :)
 
Use the return from the InputBox in your query criteria. Something like:

strCity = InputBox(yahda, yahda)
strSQL = "SELECT Employees.EMP_LNAME, Employees.EMP_FNAME " _
& "FROM Employees WHERE Employees.CITY = '" & strCity & "'"
set rstEmp = CurrentDB.OpenRecordSet(strSQL)
 
How do you want to display your data?

Here's some quick and dirty for a list box. Note the single quotes inside the
double quotes around the sInput variable.

Dim sInput As String, sResult As String

sInput = InputBox("Enter the city:", "InputBox Example")

sResult = "SELECT YourTable.* _
FROM YourTable _
WHERE (((YourTable.City)='" & sInput & "'));"

Me.List0.RowSource = sResult

HTH,
RD
 
Back
Top