PC Review


Reply
Thread Tools Rate Thread

Code to filter a database displays no rows at all

 
 
=?Utf-8?B?UGV0ZSBSb29uZXk=?=
Guest
Posts: n/a
 
      14th Nov 2007
Good afternoon!

I recorded a macro to filter a database to show records where the entry in
column 1 was between two dates thus:

Sub DateFilterOn()
Range("MainDatabaseStart").AutoFilter Field:=1, _
Criteria1:=">=23/10/2007", Operator:=xlAnd, _
Criteria2:="<=22/11/2007"
End Sub

When I run the code, it filters the database down and displays no rows at
all (which is incorrect, as there are loads of them that meet the criteria).
If I then go into Data Filter Custom manually on the first DB column, the
criteria from the code appear in the dialog box and when I click "OK", the
database is correctly filtered.

Can anyone tell me where I'm going wrong, please? Why won't my code filter
my data correctly without the manual intervention?

Thanks in advance.

pete
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      14th Nov 2007
Hi Pete

Use the US date format mm/dd/yyyy instead of the DMY you use now in the code



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Pete Rooney" <(E-Mail Removed)> wrote in message news:543A02AA-54B0-47FA-9A06-(E-Mail Removed)...
> Good afternoon!
>
> I recorded a macro to filter a database to show records where the entry in
> column 1 was between two dates thus:
>
> Sub DateFilterOn()
> Range("MainDatabaseStart").AutoFilter Field:=1, _
> Criteria1:=">=23/10/2007", Operator:=xlAnd, _
> Criteria2:="<=22/11/2007"
> End Sub
>
> When I run the code, it filters the database down and displays no rows at
> all (which is incorrect, as there are loads of them that meet the criteria).
> If I then go into Data Filter Custom manually on the first DB column, the
> criteria from the code appear in the dialog box and when I click "OK", the
> database is correctly filtered.
>
> Can anyone tell me where I'm going wrong, please? Why won't my code filter
> my data correctly without the manual intervention?
>
> Thanks in advance.
>
> pete

 
Reply With Quote
 
=?Utf-8?B?UGV0ZSBSb29uZXk=?=
Guest
Posts: n/a
 
      15th Nov 2007
Ron,

Nice to hear from you again!

As usual, spot on answer :-)

Thank you!

Pete

"Ron de Bruin" wrote:

> Hi Pete
>
> Use the US date format mm/dd/yyyy instead of the DMY you use now in the code
>
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Pete Rooney" <(E-Mail Removed)> wrote in message news:543A02AA-54B0-47FA-9A06-(E-Mail Removed)...
> > Good afternoon!
> >
> > I recorded a macro to filter a database to show records where the entry in
> > column 1 was between two dates thus:
> >
> > Sub DateFilterOn()
> > Range("MainDatabaseStart").AutoFilter Field:=1, _
> > Criteria1:=">=23/10/2007", Operator:=xlAnd, _
> > Criteria2:="<=22/11/2007"
> > End Sub
> >
> > When I run the code, it filters the database down and displays no rows at
> > all (which is incorrect, as there are loads of them that meet the criteria).
> > If I then go into Data Filter Custom manually on the first DB column, the
> > criteria from the code appear in the dialog box and when I click "OK", the
> > database is correctly filtered.
> >
> > Can anyone tell me where I'm going wrong, please? Why won't my code filter
> > my data correctly without the manual intervention?
> >
> > Thanks in advance.
> >
> > pete

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a filter functionality to my database form. What's wrong withthat code? Lothar Behrens Microsoft C# .NET 1 12th Apr 2010 01:28 PM
Worksheet change code to colour in rows in a database =?Utf-8?B?UGV0ZXIgUm9vbmV5?= Microsoft Excel Programming 7 19th May 2006 11:36 AM
Excel 2003: Can you filter rows much the same way you filter colu. =?Utf-8?B?SmVmZg==?= Microsoft Access 2 6th Apr 2005 02:00 AM
Can I filter rows or create aggregate rows with DataTable? =?Utf-8?B?TXJOb2JvZHk=?= Microsoft C# .NET 3 22nd Oct 2004 05:05 PM
Hidden rows > Database Filter Charley Kyd Microsoft Excel Programming 3 3rd Mar 2004 12:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:01 PM.