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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date range using setGenFilter 1

Status
Not open for further replies.

mtastad

Programmer
Feb 5, 2002
18
US
I am having trouble using setGenFilter with date ranges. I have a TCursor opened on a table and am using setGenFilter to limit the view of the TCursor. I have searched through manuals and this site, but haven't found a solution. Any suggestions? Also, thank you to the people who responded to my previous post (very helpful)!!
 
What kind of trouble are you having? Seeing nothing, seeing everything?
This kind of code should work:

daCrit[&quot;Date&quot;] = &quot;>12/31/2000, <2/1/2001&quot;
tc.setgenfilter(daCrit)

If this is what your date field filter looks like then you may have a problem in another field.
Post some code is still a problem,
Richie
 
Any error messages to share?

I've found that when dates are involved, its best to ensure that the full four digits for the year are supplied. Be aware also of the order of the mm/dd or dd/mm if using the European date format. If the BDE and the PC regional setting are not all aligned correctly, order issues arise with some functions - e.g. they can work OK interactively for queries but not in code!

 
mtstad,
FYI the most common reasons is see for problems in filtering or querying for date ranges are
1. Get No results :
a. There really are no matches (most common reason)
b. Mixing up >,< eg. &quot;<12/31/2001, >2/1/2002&quot;

2. Get Everything in table:
using OR instead of &quot;,&quot; eg. &quot;>12/31/2001 OR < 2/1/2002&quot;

Very rarely, but for the sake of completeness
3. Get Completely opposite of what you want :
combination of above eg. &quot;<12/31/2001 OR > 2/1/2002&quot;

Richie


 
Thanks for the tips - here is the code I am using:

Code:
If not tcM.open(&quot;:ESI:Q_Main.db&quot;) then
	msginfo(&quot;Error&quot;,&quot;Unable to open TC on Q_Main&quot;)
	return
endif

criteria[&quot;Date&quot;] = &quot;> date(startDate.value), < date(endDate.value)&quot;

If not tcM.setGenfilter(criteria) then
	msginfo(&quot;Error&quot;,&quot;Unable to set date range&quot;)
	return
endif
startDate and endDate are undefined fields on the form (formatted as date fields). Dates are entered into them and the user clicks a &quot;calculate&quot; button to perform an operation based on the date range. The table &quot;Q_main&quot; has a date field called &quot;Date&quot;. When I execute the code, it doesn't get through the setGenfilter method (pops up the &quot;Unable to set date range&quot; message.
 
Oh!
Try
criteria[&quot;Date&quot;] = &quot;> &quot; + string(date(startDate.value) + &quot;, < &quot; + string(date(endDate.value)

Otherwise, put a criteria.view() after setting criteria[...] and see what it says!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top