Results 1 to 4 of 4

Thread: ORDER BY problem

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    ORDER BY problem

    I am wanting to populate a ListView using the ORDER BY. I am wanting to ORDER BY on the EntryDate column which happens to be a date. It seems to work; however, its not working the way it should. Screen shots attached.

    This is what I am using:
    VB Code:
    1. Public Sub PopulateListViewSQL()
    2.     strSQL = "SELECT * "
    3.     strSQL = strSQL & "FROM Ledger "
    4.     strSQL = strSQL & "WHERE AccountNumber = '" & _
    5.     frmLedger.cboAccountNumber.Text & "' "
    6.     strSQL = strSQL & "ORDER BY EntryDate DESC"
    7.    
    8.     objCon.Execute strSQL
    9.        
    10.     PopulateListviewEntries
    11. End Sub
    12.  
    13. Public Sub PopulateListviewEntries()
    14.     OpenRecordset
    15.    
    16.     frmLedger.lvwAccountLedger.ListItems.Clear
    17.    
    18.     Do Until objRs.EOF = True
    19.    
    20.     With objRs
    21.         dteEntryDate = .Fields("EntryDate")
    22.         strTransDesc = .Fields("TransDesc")
    23.         curCredit = .Fields("Credit")
    24.         curDebit = .Fields("Debit")
    25.         intID = .Fields("id")
    26.     End With
    27.    
    28.     Set LvwItm = frmLedger.lvwAccountLedger.ListItems.Add(, , dteEntryDate)
    29.    
    30.     With LvwItm
    31.         .SubItems(1) = strTransDesc
    32.         .SubItems(2) = Format(curCredit, "0.00")
    33.         .SubItems(3) = Format(curDebit, "0.00")
    34.         .SubItems(4) = intID
    35.     End With
    36.    
    37.     objRs.MoveNext
    38.     Loop
    39. End Sub
    Attached Images Attached Images   

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: ORDER BY problem

    whats not working?

    the second png looks fine.. or am i missing something?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: ORDER BY problem

    Quote Originally Posted by Static
    whats not working?

    the second png looks fine.. or am i missing something?
    in 1.png, 11/9/2006 comes before 11/3/2006 and it shouldnt.
    in 2.png, 11/17/2006, 11/15/2006 and 11/14/2006 is coming after 11/20/2006.

    In other words, I am trying to sort the records in descending order, by date. Its sorting some but not all which is a little strange.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: ORDER BY problem

    You are nto populating the recordset by your query. It is showing old records from another query or somewhere else.

    VB Code:
    1. Public Sub PopulateListViewSQL()
    2.     strSQL = "SELECT * "
    3.     strSQL = strSQL & "FROM Ledger "
    4.     strSQL = strSQL & "WHERE AccountNumber = '" & _
    5.     frmLedger.cboAccountNumber.Text & "' "
    6.     strSQL = strSQL & "ORDER BY EntryDate DESC"
    7.    
    8. '    objCon.Execute strSQL
    9.     Set objRS = objCon.Execute strSQL     '<-- Check This line
    10.        
    11.     PopulateListviewEntries
    12. End Sub


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

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