Results 1 to 13 of 13

Thread: [RESOLVED] Filtering recordsets. Help please!

  1. #1

    Thread Starter
    Lively Member ginothegodfather's Avatar
    Join Date
    Sep 2007
    Location
    Very far...
    Posts
    75

    Resolved [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.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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 & "'"

  3. #3

    Thread Starter
    Lively Member ginothegodfather's Avatar
    Join Date
    Sep 2007
    Location
    Very far...
    Posts
    75

    Re: Filtering recordsets. Help please!

    No I didnt. What about the USER ?

  4. #4

  5. #5

    Thread Starter
    Lively Member ginothegodfather's Avatar
    Join Date
    Sep 2007
    Location
    Very far...
    Posts
    75

    Re: Filtering recordsets. Help please!

    Quote Originally Posted by RhinoBull
    What about it?
    I mean to filter recordsets 1: Betwen dates and 2: User.
    Hope i have myselfe clear.

  6. #6

  7. #7

    Thread Starter
    Lively Member ginothegodfather's Avatar
    Join Date
    Sep 2007
    Location
    Very far...
    Posts
    75

    Re: Filtering recordsets. Help please!

    Can u give me the full code pls?

  8. #8

    Thread Starter
    Lively Member ginothegodfather's Avatar
    Join Date
    Sep 2007
    Location
    Very far...
    Posts
    75

    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.

  9. #9

    Thread Starter
    Lively Member ginothegodfather's Avatar
    Join Date
    Sep 2007
    Location
    Very far...
    Posts
    75

    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

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Filtering recordsets. Help please!

    Quote 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.

  11. #11

  12. #12
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Filtering recordsets. Help please!

    Your problem is here:


    "'" And "USER='"

    Try This:
    MsgBox "'" And "USER='"

    It gives me a type mismatch.

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width