Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 15th, 2005, 06:38 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query from Form

Hi all,

How can I do a query based on a form?
I have a queryform and I pass parameters to my query.
If I leave a textboxes blank in my queryform then query must return all records from my table.

How can I do this?

Thanks in advance
-vemaju

__________________
-vemaju
 
Old September 15th, 2005, 08:54 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Vemanju,

How many parameters?

Kevin

dartcoach
 
Old September 15th, 2005, 09:08 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I have about 8-12 parameters

 
Old September 15th, 2005, 09:13 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Vemaju,

What happens when you run the query? Do you bring the results back to the screen or use the results for a report?

I'm thinking you can dynamically build the sql statement based on which parameters the user filled in.

Can you post the query sql? That way I can see what you have now.

Kevin

dartcoach
 
Old September 15th, 2005, 09:28 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Kevin

It should be something like this

SELECT Customers.CompanyName, Customers.ContactName, Customers.ContactTitle
FROM Customers
WHERE (((Customers.CompanyName)=[Forms]![Customers]![CustomerID]) AND ((Customers.ContactName)=[Forms]![Customers]![CompanyName]) AND ((Customers.ContactTitle)=[Forms]![Customers]![ContactTitle]));

-vemaju

 
Old September 15th, 2005, 10:24 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Guys,

A quick way to do this is to use the NZ function. e.g.,

SELECT Customers.CompanyName, Customers.ContactName, Customers.ContactTitle
FROM Customers
WHERE (((Customers.CompanyName) Like NZ([Forms]![Customers]![CustomerID],'*')) AND ((Customers.ContactName) Like NZ([Forms]![Customers]![CompanyName],'*')) AND ((Customers.ContactTitle) Like NZ([Forms]![Customers]![ContactTitle],'*')));

Then whenever you have a null text box the query uses the wild card instead.

Any good to you?

Jon
 
Old September 15th, 2005, 10:26 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Cool, that's much better than dynamically creating the sql.

Kevin

dartcoach
 
Old September 15th, 2005, 10:43 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi all,

Thank you for good and quick answer.
I have tried NZ-function, but I had word LIKE in wrong place.

-vemaju






Similar Threads
Thread Thread Starter Forum Replies Last Post
Query data in form Vince_421 Access 2 February 1st, 2007 10:45 AM
Sub Form Query Brendan Bartley Access 2 September 27th, 2006 09:00 AM
Linking a query to a form hikinfool Access 3 February 24th, 2006 06:09 PM
create query through a form madeira Access 4 September 26th, 2003 06:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.