473,387 Members | 1,520 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,387 software developers and data experts.

recordset limiting

Hello,

I am trying to limit the records in a recordset between two dates.
With a view to count the records and use that count later.

So, to test my code I created a continuous form with two unbound text
boxes to enter the dates and a button to apply the dates to the
recordsource.

Using the tips and hints from various sources, I figured the dates had
to be in American format. Thought I had cracked it, but testing has
proven that I get very anomalous results.

The table:

HolidayDate HolidayName
02-Jan-06 New Years Day
14-Apr-06 Good Friday
17-Apr-06 Easter Monday
01-May-06 Early May Bank Holiday
29-May-06 Spring Bank Holiday
28-Aug-06 Summer Bank Holiday
25-Dec-06 Christmas Day
26-Dec-06 Boxing Day
01-Jan-07 New Years Day

and the code:
__________________________________________________ ___________________________
Private Sub cmdDateLimiter_Click()
On Error GoTo Err_cmdDateLimiter_Click

Dim datStart As Date
Dim datEnd As Date

datStart = Format$(Me.txtStartDate, "mm\/dd\/yyyy")
datEnd = Format$(Me.txtEndDate, "mm\/dd\/yyyy")

Me.RecordSource = "Select * from tblHolidays where HolidayDate between
#" & datStart & "# and #" & datEnd & "#"

Me.Requery

Exit_cmdDateLimiter_Click:
Exit Sub

Err_cmdDateLimiter_Click:
MsgBox Err.Description
Resume Exit_cmdDateLimiter_Click

End Sub
__________________________________________________ ___________________________
When I enter "14-Apr-06" for txtStartDate and "01-May-06" for
txtEndDate

I get the last six records from "01-May-06 Early May Bank Holiday"
onwards. I would expect to get 3 records, "14-Apr-06" to "01-May-06"
inclusive.

Have I done something obviously wrong? or have I wandered down the
wrong track?

I appreciate any comments.

SEAN

Apr 26 '06 #1
4 1727
"badboybrown" <se*****@gmail.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Hello,

I am trying to limit the records in a recordset between two dates.
With a view to count the records and use that count later.

So, to test my code I created a continuous form with two unbound text
boxes to enter the dates and a button to apply the dates to the
recordsource.

Using the tips and hints from various sources, I figured the dates had
to be in American format. Thought I had cracked it, but testing has
proven that I get very anomalous results.

The table:

HolidayDate HolidayName
02-Jan-06 New Years Day
14-Apr-06 Good Friday
17-Apr-06 Easter Monday
01-May-06 Early May Bank Holiday
29-May-06 Spring Bank Holiday
28-Aug-06 Summer Bank Holiday
25-Dec-06 Christmas Day
26-Dec-06 Boxing Day
01-Jan-07 New Years Day

and the code:
__________________________________________________ ___________________________
Private Sub cmdDateLimiter_Click()
On Error GoTo Err_cmdDateLimiter_Click

Dim datStart As Date
Dim datEnd As Date

datStart = Format$(Me.txtStartDate, "mm\/dd\/yyyy")
datEnd = Format$(Me.txtEndDate, "mm\/dd\/yyyy")

Me.RecordSource = "Select * from tblHolidays where HolidayDate between
#" & datStart & "# and #" & datEnd & "#"

Me.Requery

Exit_cmdDateLimiter_Click:
Exit Sub

Err_cmdDateLimiter_Click:
MsgBox Err.Description
Resume Exit_cmdDateLimiter_Click

End Sub
__________________________________________________ ___________________________
When I enter "14-Apr-06" for txtStartDate and "01-May-06" for
txtEndDate

I get the last six records from "01-May-06 Early May Bank Holiday"
onwards. I would expect to get 3 records, "14-Apr-06" to "01-May-06"
inclusive.

Have I done something obviously wrong? or have I wandered down the
wrong track?

I appreciate any comments.

SEAN


I would have expected these

datStart = Format$(Me.txtStartDate, "mm\/dd\/yyyy")
datEnd = Format$(Me.txtEndDate, "mm\/dd\/yyyy")

to read

datStart = Format(Me.txtStartDate, "mm/dd/yyyy")
datEnd = Format(Me.txtEndDate, "mm/dd/yyyy")

Also, try declaring your date containers as Variant types instead of dates.

Regards,
Keith.
www.keithwilby.com
Apr 26 '06 #2
Thank you.

Declaring the containers as Variant types has done the trick. Would it
be too much to ask if you could explain why? I would've thought that
declaring them as dates would be required as they were being used
against dates.

as for the formatting of the dates, I used the tips from Allen Browne's
site and it states:

"Unfortunately, Format() replaces the slashes with the date separator
character defined in Control Panel | Regional Settings, so you must
specify literal slashes in the format string by preceding the slash
with backslashes."

Thanks once again.

I'd never get anything done without reading this site... I also get
nothing done because I'm reading this site.

Apr 26 '06 #3
"badboybrown" <se*****@gmail.com> wrote in message
news:11**********************@t31g2000cwb.googlegr oups.com...
Thank you.

Declaring the containers as Variant types has done the trick. Would it
be too much to ask if you could explain why? I would've thought that
declaring them as dates would be required as they were being used
against dates.
To be honest I can't remember, I think it's related to the time element of
the date data but I'm not sure. What I do remember is having endless
trouble trying to deal with date values with date type containers. Perhaps
one of the MVPs could jump in and explain why ...

as for the formatting of the dates, I used the tips from Allen Browne's
site and it states:

"Unfortunately, Format() replaces the slashes with the date separator
character defined in Control Panel | Regional Settings, so you must
specify literal slashes in the format string by preceding the slash
with backslashes."


Duly noted, thanks.

Keith.
Apr 26 '06 #4
badboybrown wrote:
Dim datStart As Date
Dim datEnd As Date

datStart = Format$(Me.txtStartDate, "mm\/dd\/yyyy")
datEnd = Format$(Me.txtEndDate, "mm\/dd\/yyyy")


Actually, the reason Keith's solution works is because you've made your
variables variants and access is correctly interpreting the format
functions as variant strings.

The format function returns a "variant (string)" (from the help on format).

Keith's solution seesm to be working for you. My own solution would
have been to keep the variables as dates and use either of the following
in place of format:

1) dateserial - see help on this function - if you can make sure you can
reliably breakdown what is entered into the correct year, month and
date, regardless of the order, you've got it licked

or

2) datevalue - again, see help. I like this one for Access dates
myself, as the user will be able to enter the date in the way their
computer is used to handling them and datevalue will correctly interpret it.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Apr 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lyn | last post by:
If I have a form where the RecordSource property is set to the name of a table, then on opening the SingleForm form I can cycle through all the records in the table one at a time via Next and...
2
by: Jo Davis | last post by:
access fe and access be. later the be might be sql server I don't want people to pass this application around. And I want control over usage. I want it to 'expire' after a while. I have fairly...
6
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is...
4
by: N J | last post by:
Hi, I ahve developed a program using access and am distributing it using MDE's, I ahve had many requests for a demo. I was thinking of limiting the number of records to say 100? If anyone has...
3
by: Peter Silva | last post by:
Hi folks, I have a need in a network data distribution application to send out data to folks who want it using the protocol of their choice. IŽd like it to support a variety of protocols and I...
2
by: Jeff Gardner | last post by:
Greetings: I've a script written for paging through a given recordset with page links, etc. I want to be able to limit the number of page numbers displayed as a large query may result in 100 or...
11
by: endy_tj | last post by:
In vb6 I can use ADO's recordset to retrieve data from database, work on the data, then send the modifications back to the database. I use disconnected recordset, and call updatebatch to send...
4
WyvsEyeView
by: WyvsEyeView | last post by:
I have a datasheet form in which one field is a combo box that will potentially contain hundreds of records. I've read about several methods of speeding up such combo boxes or limiting their initial...
2
by: jghouse | last post by:
Everyone, Hopefully you can help me with a little problem I am having. I have a need to limit the records shown in a form by a few different criteria. I also need these records to be editable....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.