If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > count numbers of records untill a specific date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-12, 01:57
leholt leholt is offline
Registered User
 
Join Date: Jan 2012
Posts: 4
count numbers of records untill a specific date

hi there
Hope someone can help me out here.
I have a Access 2003 database which I access through ASP website.
I want to count the numbers of records I had one year earlier then the present date. My code looks like this

Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorType = adOpenStatic
objRS.ActiveConnection = Con

objRS.Open="Select * FROM NEWSTUDENTS_2011 WHERE
STUDENT_status < '2' and entry_date < Date()-365"

number_student_2011 = objRS.RecordCount

I guess my use of date format is terrible wrong - but hours of searching and trying different alternatives - haven't worked so far. :-(

The recordcount I recieve is too big ....
whats wrong ..?
thanks for any response

Otto Leholt
Reply With Quote
  #2 (permalink)  
Old 01-21-12, 02:59
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Change:
Code:
entry_date < Date()-365"
to:
Code:
entry_date < DateAdd("yyyy", -1, Date)
Note: If STUDENT_status is defined as a numeric data type, also change:
Code:
STUDENT_status < '2'
to:
Code:
STUDENT_status < 2
Note2: You'll possibly need to use:
Code:
objRS.MoveLast
before retrieving a significant value from the RecordCount property of the RecordSet.
__________________
Have a nice day!

Last edited by Sinndho; 01-21-12 at 03:07.
Reply With Quote
  #3 (permalink)  
Old 01-21-12, 03:22
leholt leholt is offline
Registered User
 
Join Date: Jan 2012
Posts: 4
still I get too many numbers

Hi - thanks for your quick response..

I used your suggestion - in this way :

objRS.Open="Select * FROM newstudent_2011 WHERE entry_date < "&DateAdd("yyyy", -1, Date)&" AND student_status < '2' "
objRS.Movelast

antal_elever_2011 = objRS.RecordCount

BUT I still get too many recordcounts ... so still something here isn't working right :-(
Reply With Quote
  #4 (permalink)  
Old 01-21-12, 03:26
leholt leholt is offline
Registered User
 
Join Date: Jan 2012
Posts: 4
my entry_date field is a text field !

ohh - I just realized that my datafield 'entry_date ' is a TEXT field and not the date type - I guess that may be the problem or what ...?
Reply With Quote
  #5 (permalink)  
Old 01-21-12, 03:48
leholt leholt is offline
Registered User
 
Join Date: Jan 2012
Posts: 4
Talking Now I got it right..

hi again -
now I changed my 'entry_date' field from TEXT to Dateformat type
and so my original code :

entry_date < Date()-365

actually seems to work .. so far only tested on localhost , but anyway ..:-)
But I do admit that this may not be the right way to work around with date ..

thanks for your response so far :-)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On