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
Solved

Selecting Using Date in SQL Query within Visual Basic

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

839 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