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!

Query Form 1

Status
Not open for further replies.

jcpelejo

Programmer
Jul 29, 2001
70
US
Hello. I would like to create a query form that can query a client by the [Client Name] and/or [city] and/or [Client Number] and/or [Phone Number] and display in a subform the first 10 results. Please advise.
 

The query would something look like this. Create the query, save it and execute it after the user inputs the criteria.

Select Top 10
[Client Name], [City], [Client Number], [Phone Number]
From TableName
Where [Client Name] Like "*" & NZ([Forms].[FormName].txtClientName,"") & "*"
Or [City] Like "*" & NZ([Forms].[FormName].txtCity,"") & "*"
Or [Client Number] = [Forms].[FormName].txtClientNo
Or [Phone Number] Like "*" & NZ([Forms].[FormName].txtPhone,"") & "*"

---------------------------

FormName and TableName should be changed to the names of your form and table, respectively. txtClientName, txtCity, txtClientNo and txtPhone should be changed to the names of the text boxes on your search form. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Hello Terry,

I wrote this command in the AfterUpdate PROC:
Private Sub txtClientName_AfterUpdate()
[Client Selection].Requery
End Sub

For the query I wrote this:
SELECT TOP 10 Client.ClientName, Client.PhoneNumber, Client.City, Client.Province, Client.ClientNumber
FROM Client
WHERE (((Client.ClientName) Like "*" & NZ([Forms]![Client Selection]![txtClientName],"") & "*")) OR (((Client.City) Like "*" & NZ([Forms]![Client Selection]![txtCity],"") & "*")) OR (((Client.PhoneNumber) Like "*" & NZ([Forms]![Client Selection]![txtPhoneNumber],"") & "*"));

I am not sure what I am doing wrong in order to get the proper results. I used the subform wizard to create the subform with the query results but it is shows the first ten records in my [Client] table. My main form name is [Client Selection] and my subform name is [Client Selection subform]. Please advise. Thank you.
 

I see the error of my query. I apologize for the misdirection. Use AND between the criteria rather than OR.

WHERE (((Client.ClientName) Like "*" & NZ([Forms]![Client Selection]![txtClientName],"") & "*"))
AND (((Client.City) Like "*" & NZ([Forms]![Client Selection]![txtCity],"") & "*"))
AND (((Client.PhoneNumber) Like "*" & NZ([Forms]![Client Selection]![txtPhoneNumber],"") & "*")); Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
It is working in datasheet view. I was wondering if there is a way of getting the results in continous form view and having the results display a radio button so that when the button is pressed, it stores the value of the result in a table. Please advise.
 
I am also having a problem when I type in a value in and of the text boxes and press tab, it does not update the results in the subform until I change the view to design view and back to form view. Please advise.
 

Have you tried using <SubForm>.ReQuery after updating the main form? Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top