Solved

Selecting Using Date in SQL Query within Visual Basic

Posted on 2008-10-29
4
172 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 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

Technology Partners: 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

705 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