Solved

How to filter record with SQL by comparing the date store in ACCESS?

Posted on 2000-05-04
4
188 Views
Last Modified: 2010-05-02
My data is store at ACCESS. I've try use SQL statement in Visual Basic to filter out records that I want, but cannot. Like,
step1 :OldestDay=Date()-10

step2 : "select * from RecordingTable where StartTime <= OldestDays"

I try to use VisData to build Query also not working for Date data, it always change to String and if I change by to Date format , error will occur.
0
Comment
Question by:candysoong
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
HunterKiller earned 50 total points
ID: 2777697
If OldestDay is a variable, and StartTime is an existing field in your RecordingTable, here is your answer:

Dim OldestDay as Date

OldestDay = DateAdd("d", -10, Date)

"SELECT * FROM RecordingTable WHERE StartTime <= " & OldestDay
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2777845
You will need to surround the date with # like this:
"SELECT * FROM RecordingTable WHERE StartTime <= #" & OldestDay & "#"

0
 
LVL 1

Expert Comment

by:HunterKiller
ID: 2779202
or use the TimeValue function, that I forgot =]

"SELECT * FROM RecordingTable WHERE StartTime <= TimeValue(' " & OldestDay & "')"
0
 

Expert Comment

by:rfyl
ID: 2801551
If you want your program to work where the date format is not American (mm/dd/yyyy), then you will need to format it... e.g.

strSQL = "SELECT * FROM RecordingTable WHERE StartTime <= " & "#" & Format$(OldestDay, "mm/dd/yy") & "#"

See:
http://msdn.microsoft.com/library/devprods/vs6/vbasic/vbcon98/vbconsqlqueriesbasedondates.htm
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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