Solved

Parameter Query with wildcard

Posted on 2013-05-25
10
366 Views
Last Modified: 2013-05-25
Hi,
I have this parameter query Like "*" & [Date] & "*"

I would like to be able to add a date range. Unfortunately I can't use the standard Between - And parameter because my data is from a linked table that has the date and time in the field.

Thanks,
Ward
0
Comment
Question by:draw58
10 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 39196596
Ward

What dates are you actually looking for?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39196600
If you need to do a Date range comparison (user inputs the range), without the time portion, then switch to SQL View and use this for the WHERE clause of your query:

WHERE DatePart([YourDateTimeFIeld]) BETWEEN [Start Date] AND [End Date]
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39196651
personally, i would recommend using

"where [datefield] >= #" & [from date] & "# and [date field] < #" & dateadd("d", 1, [thru date]) & "#"
0
 

Author Comment

by:draw58
ID: 39196684
This is my SQL. I am getting an error "Wrong number of arguments used with function in query expression.

SELECT [Sales History].TKT_NO, [Sales History].TKT_DT, [Sales History].SLS_REP, [Sales History].STR_ID, [Sales History].ITEM_NO, [Sales History].DESCR, [Sales History].CATEG_COD, [Sales History].QTY_SOLD, [Sales History].EXT_COST, [Sales History].EXT_PRC, [Sales History].PRC_OVRD_REAS, [Sales History].NAM, [Sales History].CUST_NO, [Sales History].EMAIL_ADRS_1, [Sales History].NAM1, [Sales History].ITEM_VEND_NO, [Sales History].SUBCAT_COD, [Sales History].PRC_1, [EXT_PRC]-[EXT_COST] AS PROFIT, ([EXT_PRC]-[EXT_COST])/[EXT_PRC] AS [Profit Percent]
FROM [Sales History]
WHERE DatePart([TKT_DT]) BETWEEN [Start Date] AND [End Date]
0
 
LVL 77

Expert Comment

by:peter57r
ID: 39196689
The function should be DateValue() not DatePart()
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:draw58
ID: 39196734
I get "data type mismatch" when i switch to DateValue
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39196740
Do you have nulls in your data?

Try

DateValue(nz(yourdatefield, #1/1/1900#))
0
 

Author Comment

by:draw58
ID: 39197123
Nope, I don't have any nulls. Where do I put DateValue(nz(yourdatefield, #1/1/1900#)) ?
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39197137
Try this:


SELECT [Sales History].TKT_NO, [Sales History].TKT_DT, [Sales History].SLS_REP, [Sales History].STR_ID, [Sales History].ITEM_NO, [Sales History].DESCR, [Sales History].CATEG_COD, [Sales History].QTY_SOLD, [Sales History].EXT_COST, [Sales History].EXT_PRC, [Sales History].PRC_OVRD_REAS, [Sales History].NAM, [Sales History].CUST_NO, [Sales History].EMAIL_ADRS_1, [Sales History].NAM1, [Sales History].ITEM_VEND_NO, [Sales History].SUBCAT_COD, [Sales History].PRC_1, [EXT_PRC]-[EXT_COST] AS PROFIT, ([EXT_PRC]-[EXT_COST])/[EXT_PRC] AS [Profit Percent]
FROM [Sales History]
WHERE DateValue(nz([TKT_DT], #1/1/1900#)) BETWEEN CDate([Start Date]) AND CDate([End Date])

Open in new window

0
 

Author Closing Comment

by:draw58
ID: 39197249
Perfect! Thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now