?
Solved

Selecting Using Date in SQL Query within Visual Basic

Posted on 2008-10-29
4
Medium Priority
?
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 750 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 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