Solved

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

Posted on 2000-05-04
4
186 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 69

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 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

19 Experts available now in Live!

Get 1:1 Help Now