|
-
Jan 5th, 2008, 11:15 AM
#1
Thread Starter
Lively Member
[RESOLVED] Filtering recordsets. Help please!
To filter the recordsets with 2 variables (date and user) i use this code:
Code:
Set mrs = New ADODB.Recordset
With mrs
.ActiveConnection = cnn
.Source = "Select * From TABLE"
.Open "select F1,DATE,F3,USER,F5 from TABLE"
End With
mrs.Filter = "DATE='" & txtDate.Text & "' and USER='" & txtUser.Text & "'"
Set MSHFlexGrid1.Recordset = mrs
Now I want to filter recordsets betwen dates. I mean: "from txtData1 to txtData2 and txtUser too". How can i make this? Can anybody help me please? Thnx.
-
Jan 5th, 2008, 11:19 AM
#2
Re: Filtering recordsets. Help please!
Have you tried this yet?
Code:
mrs.Filter = "DATE Between '" & txtDate1.Text & "' And '" & txtDate2.Text & "'"
or this...
Code:
mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "'"
-
Jan 5th, 2008, 11:27 AM
#3
Thread Starter
Lively Member
Re: Filtering recordsets. Help please!
No I didnt. What about the USER ?
-
Jan 5th, 2008, 11:44 AM
#4
Re: Filtering recordsets. Help please!
What about it?
-
Jan 5th, 2008, 11:53 AM
#5
Thread Starter
Lively Member
Re: Filtering recordsets. Help please!
 Originally Posted by RhinoBull
What about it? 
I mean to filter recordsets 1: Betwen dates and 2: User.
Hope i have myselfe clear.
-
Jan 5th, 2008, 12:08 PM
#6
Re: Filtering recordsets. Help please!
So add the "user filter" (as you already did) to what I posted...
-
Jan 5th, 2008, 03:15 PM
#7
Thread Starter
Lively Member
Re: Filtering recordsets. Help please!
Can u give me the full code pls?
-
Jan 5th, 2008, 03:24 PM
#8
Thread Starter
Lively Member
Re: Filtering recordsets. Help please!
I used this code:
Code:
mrs.Filter = "DATE Between '" & txtDate1.Text & "' And '" & txtDate2.Text & "'" And "USER='" & txtUser.Text & "'"
or
Code:
'mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "'" And "USER='" & txtUser.Text & "'"
and it tells me: Error13. Type mismatch. Where is my error?
P.S. In my database the data type of the field DATE is text. Is this the error?
Last edited by ginothegodfather; Jan 5th, 2008 at 03:29 PM.
-
Jan 5th, 2008, 03:36 PM
#9
Thread Starter
Lively Member
Re: Filtering recordsets. Help please!
When i use
Code:
mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "'"
it works fine but when I use
Code:
mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "'" And "USER='" & txtUser.Text & "'"
it tells me type mismatch. Where is the problem
-
Jan 5th, 2008, 03:49 PM
#10
Re: Filtering recordsets. Help please!
 Originally Posted by ginothegodfather
Code:
mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "'" And "USER='" & txtUser.Text & "'"
it tells me type mismatch. Where is the problem
You have some extra quotes in the string
Code:
mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "' And USER = '" & txtUser.Text & "'"
P.S. Your query actually works on the date filtering? You mentioned the db date field is text, is it formatted like yyyymmdd? Otherwise, I would imagine any correct filtering is just coincidence/lucky.
-
Jan 5th, 2008, 03:50 PM
#11
Re: Filtering recordsets. Help please!
Highlighted "And" must be part of a your entire string instead:
mrs.Filter = "DATE >= '" & txtDate1.Text & "' And DATE <= '" & txtDate2.Text & "' And USER = '" & txtUser.Text & "'"
-
Jan 5th, 2008, 03:51 PM
#12
Frenzied Member
Re: Filtering recordsets. Help please!
Your problem is here:
"'" And "USER='"
Try This:
MsgBox "'" And "USER='"
It gives me a type mismatch.
-
Jan 5th, 2008, 03:58 PM
#13
Re: Filtering recordsets. Help please!
What database is it?
You should not be using a reserved word as a field name. Place square brackets around it so its not interpreted as a literal.
mrs.Filter = "([DATE] >= '" & txtDate1.Text & "' And [DATE] <= '" & txtDate2.Text & "') And ([USER] = '" & txtUser.Text & "')"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|