Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 23rd, 2007, 09:29 AM
Registered User
Join Date: Feb 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO - SELECT FROM [Tablename] WHERE [MyDate] < ...

Hi, i post from Italy, and i have the following question for you about Excel VBA

I am trying to import records from a closed Access DB, but i don't know how to select DBfields according to a specified date.
I mean:

i want to select only the records where the field 'DateOfBirth' is < than 'MyDate', f.e. 01/02/1975.

i tried with the following code, but the VBA has gone debugging.

szSQL = "SELECT * FROM RAS WHERE [MyDate] > [DateOfBirth]"rs.Open szSQL, cn, adOpenKeyset, adLockOptimistic, adCmdText

could you please tell me where is the error?
thaenks in advance


Old February 23rd, 2007, 01:31 PM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts

Hmm... I'm assuming MyDate and DateOfBirth are both date fields and are also named in the database without spaces?
In Tools > References add "ActiveX Data Objects Recordset 2.6 Library" and "Microsoft ActiveX Data Objects 2.6 Library" and Try this:

Dim Current_Connection as ADODB.Connection, oCommand as ADODB.Command, rsRecordset as Recordset, sSQL as string
sSQL = "Select * From RAS Where [MyDate] > [DateOfBirth];"
Set Current_Connection = New ADODB.Connection
Current_Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
Current_Connection.Open "C:\My.mdb"
Set oCommand = New ADODB.Command
Set oCommand.ActiveConnection = Current_Connection
Set rsRecordset = New ADODB.Recordset
rsRecordset.Open sSQL, Current_Connection, adOpenStatic
if rsRecordset.RecordCount < 1 then
  msgbox "No records found matching criteria",,"No Records Returned"
  ***Do Desired Manipulation with rsRecordset***
end if

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with <SELECT <OPTION pegarr Classic ASP Basics 8 May 14th, 2008 09:49 AM
<select> </select> prabhash_singh11 PHP How-To 2 March 11th, 2008 09:08 AM
Using mydate in a dropdown list ssonnier VB How-To 0 August 30th, 2006 02:38 PM
Where can i download <<Fast Track ADO.NET C! Editi liuxiao_lx123 Wrox Book Feedback 1 June 21st, 2004 09:26 AM
ADO COleDateTime and day <= 12 widget Access 0 May 14th, 2004 08:41 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.