Results 1 to 5 of 5

Thread: [RESOLVED] Sort Recordset On Form

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED] Sort Recordset On Form

    I have added the ability to search records on a form. I am trying to sort the results of the search by related field the search was conducted on, but I am having problems because the sort property doesn't seem to do anything.

    VB Code:
    1. Dim strDatabaseField As String
    2.     Dim intBookmark As Integer
    3.    
    4.     If cboCriteriaField.text = "" Then
    5.         lblResults.Caption = "* Select A Search Criteria"
    6.     ElseIf txtSearch.text = "" Then
    7.         lblResults.Caption = "* Enter Search Text"
    8.     Else
    9.         '
    10.         ' Save the information of before the query.
    11.         '
    12.         intBookmark = Data.Recordset.AbsolutePosition + 1
    13.         strDatabaseField = Replace(cboCriteriaField.text, " ", "")
    14.         Data.Recordset.Sort = strDatabaseField ' Sort the recordset before searching
    15.         Data.Recordset.FindFirst strDatabaseField & " LIKE '" & Sql(txtSearch.text) & "*'"
    16.        
    17.         If Data.Recordset.NoMatch Then
    18.             '
    19.             ' Restore the previous settings
    20.             '
    21.             Data.Recordset.Move intBookmark - 1
    22.             lblResults.Caption = "* No Matchs Found"
    23.         Else
    24.             lblResults.Caption = ""
    25.             txtSearch.text = ""
    26.         End If
    27.     End If

    The initial recordset of the data control is to a single table using the following SQL.
    VB Code:
    1. Me.Data.RecordSource = "SELECT * FROM tblArchive"

    Is there any reason the sort property isn't actually sorting anything?

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

  2. #2
    Addicted Member Cristian's Avatar
    Join Date
    Jun 2006
    Posts
    228

    Re: Sort Recordset On Form

    Is your recordset's property cursorlocation set to AdUseClient?
    Maybe you must call recordset.moveFirst() before search !!

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

    Re: Sort Recordset On Form

    Sounds like your using the ADO Data control. Its a bound object and in VB 6 bound objects always give you more headaches then manually writting the code in pure ADO.
    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

  4. #4

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Sort Recordset On Form

    It is the ADO Data control. I will just write the code in pure ADO as you suggest Rob.

    C# - .NET 1.1 / .NET 2.0

    "Take everything I say with a grain of salt, sometimes I'm right, sometimes I'm wrong but in the end we've both learned something."
    _____________________
    Regular Expressions Library
    Connection String
    API Functions
    Database FAQ & Tutorial

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

    Re: [RESOLVED] Sort Recordset On Form

    You have just saved yourself many headaches.

    If you need any help with ADO let us know.
    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