473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Use unbound form to run query

Hi all,

I am a new Access user and just starting to get my head around some of the basic concepts, so please take it easy on me :) My company has been managing client records on excel, and I’m in the process of migrating the data over to Access 2007 (Windows XP), kind of learning as I go. I’ve managed to import the client records into a single table, and set up a “single view” form that streamlines how we input new client data. Now I’m trying to set up a “single view” form that would allow anyone with access to the database to run a query that returns whatever information they want using as few steps as possible.

So far, I’ve been able to set up this form to receive input via unbound text/date selection/check boxes, but I can’t get the criteria row of the query to reference any of the data entered in the controls. I’ve tried entering Forms!NameOfForm!NameOfUnboundField in the criteria cell of the query, but when I run the query to test it, it just puts brackets around the form name and unbound field name and prompts for parameter input.

Here’s what I’m trying to do, and I’m hoping there’s some simple hint that can get me started on the right track:

-I want to make the criteria row of the query reference the values (such as client name, date of visit, client’s region, etc) that users input into the unbound form.

-I want users to be able to select multiple values for certain fields (such as “client’s region,” that have a finite range, because they’re entered to the database from the input form using a list box) using check box controls in the form and get the query to return all associated records (as long as they meet the criteria specified in the other controls on the form).

-I want to allow users to use check boxes to specify which fields (within the returned records) the query displays, regardless of the filtering criteria set.

-Finally, I want to ensure that users can leave a control on the form blank and still get records back (for instance, if the “date” box is left blank, the query should return ALL records that meet the other filtering criteria). I’ve seen this is a problem in some related threads. Or, if it’s easier, they could “activate” a filtering criteria by clicking a check box. (“If you want to filter results by date, click here:”)

I realize I may be asking a lot, particularly with my lack of experience with Access, but I’m pretty much at the end of my rope with the help files and reading threads posted by other people. Any help would be SO appreciated!

Thanks!

Joe
Nov 5 '09 #1

✓ answered by MMcCarthy

There are a couple of things you need to check.

First of all is the form being left open while the query is running. If the form is closed the criteria will not work.

Secondly try entering the criteria as follows:
Forms![NameOfForm]![NameOfUnboundTextbox]
The brackets are required particularly if there are any spaces in the form name or the textbox name. Also you will notice that I changed the last part to NameOfUnboundTextbox rather than NameOfUnboundField. They are not necessarily the same thing. Check that the property name of the textbox is what you are using and not the field name.

Lastly make sure the unbound control is not on a subform as this is a different syntax.

Mary

4 9450
MMcCarthy
14,534 Expert Mod 8TB
There are a couple of things you need to check.

First of all is the form being left open while the query is running. If the form is closed the criteria will not work.

Secondly try entering the criteria as follows:
Forms![NameOfForm]![NameOfUnboundTextbox]
The brackets are required particularly if there are any spaces in the form name or the textbox name. Also you will notice that I changed the last part to NameOfUnboundTextbox rather than NameOfUnboundField. They are not necessarily the same thing. Check that the property name of the textbox is what you are using and not the field name.

Lastly make sure the unbound control is not on a subform as this is a different syntax.

Mary
Nov 5 '09 #2
Thanks for the post, Mary! I'm getting the form to work with the query now, after a lot of trial and error.
I'm trying to write the criteria in the query in such a way that they will filter records when only when a user enters text, and allow all records to be returned when left blank. An example of one of my criteria is:

Like nz("*"&([Forms]![NameOfForm]![NameOfUnboundTextbox])&"*", "*"), which lets the user enter a part of a field (like a client's last name, for instance), and get back all records that have a match in that field.
The problem now is that there are a lot of "null value" fields in the records, where data was never entered, and this criteria won't return any records with null values in the fields it's querying. Is there a way to use the unbound controls to filter records without excluding records with null values?

Thanks!

Joe
Nov 6 '09 #3
OK, I got it to work!!!

I am working straight out of the query now, it was simpler for me, but I was able to put together a QSL code that gives me what I want--if all parameters are left blank, the query returns everything, but as soon as text is entered in a parameter, it begins to filter by that field by whatever text is entered. I'm attaching the code for anyone else who might be trying to do a similar operation:

It's a little clumsy, I think, and probably has a few lines that are not required, but I've spent so much time with this I don't want to change it now that I've finally got it working.
Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Enter Start Date:] DateTime, [Enter End Date:] DateTime;
  2. SELECT [Client Database].Date, [Client Database].[Department], [Client Database].Office Building, [Client Database].[Client Name], [Client Database].Meeting Type, [Client Database].Region, [Client Database].City, [Client Database].[# of Meetings]
  3.  
  4. FROM [Client Database]
  5.  
  6. WHERE 
  7.  
  8. (IIf([Enter Office Building Name:] Is Null,(([Client Database].Office Building) Like "*" & [Enter Office Building Name:] & "*" Or ([Client Database].Office Building) Is Null),(([Client Database].Office Building) Like ("*" & [Enter Office Building Name:] & "*"))) 
  9.  
  10. And (IIf([Enter Client Name:] Is Null,(([Client Database].[Client Name]) Like "*" & [Enter Client Name:] & "*" Or ([Client Database].[Client Name]) Is Null),(([Client Database].[Client Name]) Like ("*" & [Enter Client Name:] & "*")))) 
  11.  
  12. And (IIf([Enter Meeting Type:] Is Null,(([Client Database].Meeting Type) Like "*" & [Enter Meeting Type:] & "*" Or ([Client Database].Meeting Type) Is Null),(([Client Database].Meeting Type) Like ("*" & [Enter Meeting Type:] & "*")))) 
  13.  
  14. And (IIf([Enter Region:] Is Null,(([Client Database].Region) Like "*" & [Enter Region:] & "*" Or ([Client Database].Region) Is Null),(([Client Database].Region) Like ("*" & [Enter Region:] & "*")))) 
  15.  
  16. And (IIf([Enter City:] Is Null,(([Client Database].City) Like "*" & [Enter City:] & "*" Or ([Client Database].City) Is Null),(([Client Database].City) Like ("*" & [Enter City:] & "*")))) 
  17.  
  18. And ((IIf(([Enter Start Date:] And [Enter End Date:]) Is Null,(([Client Database].Date) Like nz((([Client Database].Date)>=[Enter Start Date:] And ([Client Database].Date)<=[Enter End Date:]),"*")),([Client Database].Date)>=[Enter Start Date:] And ([Client Database].Date)<=[Enter End Date:]))<>False) 
  19.  
  20. And ((IIf(([Enter Department: (EX: HR)]) Is Null,(([Client Database].[Department]) Like nz(([Client Database].[Department]),"*")),(([Client Database].[Department]) Like nz([Enter Department: (EX: HR)],"*"))))<>False));
Mary, thanks to your tips, I can now link the query to the form, so my next step is to go back in and build the form to drive this query.

Thanks again!

Joe
Nov 7 '09 #4
MMcCarthy
14,534 Expert Mod 8TB
@dizzydangler
You're welcome anytime Joe.

Without knowing your database better I can't say if the criteria is correct for sure but if it ain't broke don't fix it :D
Nov 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: deko | last post by:
I need to create different recordsets based on queries that use data from unbound fields in a form. I've discovered that I can't do this, and instead need to save the data in question (usually a...
3
by: Pat | last post by:
Hello, I've used Sum() to total bound fields on a continuous form with no problem. However, I now have a continuous form, on which I use an unbound field to calculate the number of hours between...
3
by: Trevor Hughes | last post by:
I am trying to resolve a problem I'm experiencing in Access 2000. I have an unbound control which is set be code on the open event of a form. However when I try to subsequently run some code...
4
by: Lumpierbritches | last post by:
Thank you once again for any and all assistance. I'm building an application that's getting quite bulky due to the number of forms, macros and procedures. I was wondering if there's a way to use 1...
3
by: MLH | last post by:
I have a form, bound to a query. Its RecordSource property is a query named frmEnterLienAmounts. The form has a few bound controls and some unbound controls. The unbound controls are calculated...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
31
by: DWolff | last post by:
I'm somewhat new to Access, and have no VB experience at all (except for modifying existing code where obvious). I built a data entry form that works fine. Typically, a client will call in and...
3
by: Richard | last post by:
How is the result of query placed in a unbound textbox ? Suppose CriteriaLookups has columns TableName, KeyColumn, KeyValue, DataColumn Foo,x,11,xhat Bar,z,3,xyzzy And
7
by: DeZZar | last post by:
Hi all, Unfortunately I am quite a novice with Access!! I've created a number of data bases for my work however becuase my skills are limited to really built in functionality and wizards my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.