Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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


Reply With Quote
  #2 (permalink)  
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

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 09:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.