Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access 2003:  Query By Forms When Date Field Is Skipped by User

Posted on 2013-01-07
12
Medium Priority
?
440 Views
Last Modified: 2013-01-09
I am building some queries using a Query By Form method.  

I am building them so the user can select 1 or more unbound texbox fields in the search form (called QBF_Incident) to determine the paramters.  Any field left blank shoudl be excluded from the parameters.

The query I am having issues with involves a date paramter.  If the user enter in a Date field along with the other fields (or leave the other field empty) all is fine.

 However, if the date field is left empty (and the other field do or do not have an entry), a error code is generated (Run-time error '2001'; You canceled the previous operation.)  What should happen is if the date is empty, return the records for any date.

The acutal Query Date field consists of the following:

Field:  ReportedDate
Table: Incident
Sort:
Show: (Is checked)
Criteria: [Forms]![QBF_Incident].[WhatDate]

The other field has the following:
Field: TypeCall
Table: Incident
Sort:
Show: (is checked)
Criteria: Like [Forms]![QBF_Incident].[WhatIncident] & "*"

The (QBF_Incident) form used has a search button using VBA to run this query and I have a reset button that resets the values to "".

I have a similar query that doens't include dates that works fine.  

What do I have to have different when ignoring dates as parameters?

Thanks,

Joe
0
Comment
Question by:jtflex
  • 3
  • 2
  • 2
  • +3
12 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38753374
If I am understanding your request here:
<Any field left blank shoudl be excluded from the parameters.>
...One quick technique to ignore a criteria if it is left empty:

Like "*" & [Forms]![QBF_Incident].[WhatIncident] & "*"


Does this *Have* to be done by query by form?
There are many other ways to do what you are asking...
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38753376
Maybe
Criteria:Iif(isnull([Forms]![QBF_Incident].[WhatDate]), >#1/1/1900#, [Forms]![QBF_Incident].[WhatDate])
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38753405
Nope.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38753448
try this criteria


criteria : nz([Forms]![QBF_Incident].[WhatDate],>#1/1/1900#)
0
 
LVL 31

Expert Comment

by:hnasr
ID: 38753517
Upload a sample database.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38753796
You can use:

Criteria: IIf([Forms]![QBF_Incident].[WhatDate] Is Null,[YourQueryDateField],[Forms]![QBF_Incident].[WhatDate])

/gustav
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38755231
jtflex,

As you can see, there are a lot of ways to approach this.
In fact, the posts made after mine were a bit more refined than my quick suggestion.
So I'll back out now and let you continue with the existing experts.

;-)

Jeff
0
 

Author Comment

by:jtflex
ID: 38755719
Thanks for all the responses, I tried two variations, one from jerryb30 and the other from cactus-data as follows:

IIf([Forms]![QBF_Incident].[WhatDate] Is Null,([Incident].[ReportedDate])>#1/1/1900#,[Forms]![QBF_Incident].[WhatDate])

IIf(IsNull([Forms]![QBF_Incident].[WhatDate]),([Incident].[ReportedDate])>#1/1/1900#,[Forms]![QBF_Incident].[WhatDate])

I no longer get a error message, however, no data is returned either.  If a put a date in the form, I do get data back so I know the 2nd part of this IIF statement is working.

Any thoughts?

Joe
0
 
LVL 52

Accepted Solution

by:
Gustav Brock earned 1600 total points
ID: 38755741
Try mine:

IIf([Forms]![QBF_Incident].[WhatDate] Is Null,[Incident].[ReportedDate],[Forms]![QBF_Incident].[WhatDate])

or just:

IIf([Forms]![QBF_Incident].[WhatDate] Is Null,[ReportedDate],[Forms]![QBF_Incident].[WhatDate])

/gustav
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 400 total points
ID: 38755745
try this


IIf(IsNull([Forms]![QBF_Incident].[WhatDate]),([Incident].[ReportedDate]),[Forms]![QBF_Incident].[WhatDate])


or


IIf(IsNull([Forms]![QBF_Incident].[WhatDate]),[ReportedDate],[Forms]![QBF_Incident].[WhatDate])
0
 

Author Closing Comment

by:jtflex
ID: 38756262
Thanks both solutions work perfectly, I am giving more points to cactus-data as his solution was posted eariler, I just failed to understand it.  

But thank you also capricorn1 and all the others out there who helped me with this also.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38758045
You are welcome!

/gustav
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question