AllExperts > Visual Basic 
Search      
Visual Basic
Volunteer
Answers to thousands of questions
 Home · More Visual Basic Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Robert Nunemaker
Expertise
String manipulation, Database access and usage, Class creation, and encapsulation are my strong suits. Active X Controls and DLL`s also. Although I don`t deal with Crystal - frankly because I don`t like it; I prefer to do things manually.

Experience
Employment history: Programmed with the Air Force for 15 years, and have continued in the private sector for the past 1 year. Used VB (all versions) for the past 8 years.

Organizations: MCP and MCSD certified.

Education: Computer Science Bachelor degree.

Awards: MCP and MCSD certified.

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Find data between Dates

Visual Basic - Find data between Dates


Expert: Robert Nunemaker - 1/9/2009

Question
Hi,

I am using Microsoft Access as a database and VB 6 as programming language.


In Access I have a field of type "DateTime" in which there is data containing both Data and Time e.g. 9/1/2008 11:40 , 9/1/2008 12:15 , 9/2/2008 3:35 , 9/3/2008 9:45 etc.

I want to select data between dates. If I use BETWEEN ... AND , it is returning 0 records. Please help me how I can retreive data between dates having all the time coming between in these dates.

Looking forward for your prompt reponse.

Regards,
Mohsin

Answer
Your dates need to be wrapped in "#" symbols if they are true Date or Date/Time fields.  Example:

Dim db As New ADODB.Connection
Dim rs As New ADODB.Recordset

db.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\myFolder\myDB.mdb;Uid=Admin;Pwd=;"
db.Open
rs.Open "Select ID, InitJoinDate From myTable Where InitJoinDate Between #01/01/1990# And #12/31/2008#", db, adOpenForwardOnly, adLockReadOnly
Do Until rs.EOF
   ' Do your logic here
   rs.MoveNext
Loop
rs.Close
db.Close

Set rs = Nothing
Set db = Nothing


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.