Solved

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

Posted on 2000-05-04
4
184 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
Comment Utility
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
Comment Utility
You will need to surround the date with # like this:
"SELECT * FROM RecordingTable WHERE StartTime <= #" & OldestDay & "#"

0
 
LVL 1

Expert Comment

by:HunterKiller
Comment Utility
or use the TimeValue function, that I forgot =]

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

Expert Comment

by:rfyl
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

763 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

14 Experts available now in Live!

Get 1:1 Help Now