Solved

Selecting Using Date in SQL Query within Visual Basic

Posted on 2008-10-29
4
167 Views
Last Modified: 2012-06-21
Hello,

I am running the following code within vb and I get a "Type Mismatch" Error.

I want to select only records from the database with todays date.

Thanks for any assistance.
' Set Today's Date

                Dim todaysDate As String

                todaysDate = Day(Now) & "/" & Month(Now) & "/" & Year(Now) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
 

' Do the query

Set rs = db.OpenRecordset("SELECT logs.log_ID, logs.UserLoginName, logs.UserEmail, logs.LogText, logs.OpenClosed, logs.UserFullName, logs.logType From logs WHERE (((logs.AssignedName)='" & theName & "')) AND logs.OpenClosed = '1' AND logs.EstimatedCompletion <= '" & todaysDate & "' ORDER BY logs.EstimatedCompletion ASC")

Open in new window

0
Comment
Question by:stellaartois
  • 3
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 250 total points
ID: 22830943
Which database are you using ?

Set rs = db.OpenRecordset("SELECT logs.log_ID, logs.UserLoginName, logs.UserEmail, logs.LogText, logs.OpenClosed, logs.UserFullName, logs.logType From logs WHERE (((logs.AssignedName)='" & theName & "')) AND logs.OpenClosed = '1' AND logs.EstimatedCompletion <= getdate() ORDER BY logs.EstimatedCompletion ASC")
 
0
 
LVL 2

Author Comment

by:stellaartois
ID: 22831037
Hi thanks for the response.

Sorry, I am Using an Access Database.

Thanks,
0
 
LVL 2

Author Comment

by:stellaartois
ID: 22831051
Set rs = db.OpenRecordset("SELECT logs.log_ID, logs.UserLoginName, logs.UserEmail, logs.LogText, logs.OpenClosed, logs.UserFullName, logs.logType From logs WHERE (((logs.AssignedName)='" & theName & "')) AND logs.OpenClosed = '1' AND logs.EstimatedCompletion <= Date() ORDER BY logs.EstimatedCompletion ASC")

I looked up access date functions and Date() works great.

Thanks for your help =)
0
 
LVL 2

Author Closing Comment

by:stellaartois
ID: 31511151
Just the Date() function works a treat.

Thanks =)
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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

867 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

24 Experts available now in Live!

Get 1:1 Help Now