Results 1 to 4 of 4
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    Sorted Datasheet


    I'm getting back to an old project, and I have a general (vba recordset?) approach type question if I may. The user wants to see entries on screen as a datasheet - which will be a filtered sub form with a query recordsource - with new records appending at bottom. So I'm planning a sort field, wherein the new record will be incremented from the current record. (The user will be simply tabbing through bound controls, creating an appendation automatically when tabbing to first control of a new record.) But I will also be trapping (for a key combination) that says the user wants an "insertion " not an "append" - ie. where the new record will be "in the middle". So after computing its new sort field value, all "further down" records will need the sort field incremented by one, starting with the record just following the original current record - ie. the one beneath which the user has signaled for an insertion.

    I'm assuming this needs to be done by defining and looping through an appropriate recordset, incrementing the order-by field each time (doing a re query at end of loop), but would appreciate comments or better ideas from experienced coders. Thx, Ron

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I would probably use a control's on enter event to determine where, within the recordset, the user is. Maybe an If Then Else statement to determine if the record is new using the Me.NewRecord method.

    As for determining the greatest value for the field being used for sorting... I suppose a DMax function would be in order. I would consider using the form's recordset and cloning it to determine the max (in the interest of performance). However, the form's recordset may be filtered in a way that it does not provide the actual Max value you are looking for.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    There's no such thing as 'insertion', it's an append.
    The sort is anyway you want.

  4. #4
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Thanks for the thoughts so far. ItsMe, I like your first thought; I think you're suggesting there's no real need to trap for an "insertion." Will consider. As for the D... functions, thought I've heard they can be slow. Not sure any sort of lookup would be necessary here, because if the thing is set up right, the sorting field of the new record will always be an increment of the current record's sorting field, regardless of where the cursor is in the set.

    Ranman, I think you allude to the fact that database records are analogous to blocks dropped in a bucket and you can't sort them unless they are numbered on one face. (Apologies to whoever first posted that analogy, but it's helped me and I wish the point were emphasized more for (us non-trained) newbies). But the user wants the records to appear ordered on screen as he prepares it. (It's a chronological series of events.) That's why I put quotes around words like "insertion." So of course I need the sort. The question is what's the best VBA strategy to simulate an insertion? Thanks, -Ron
    Last edited by RonL; 09-10-2014 at 04:29 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Sub Form's ID# Not Sorted
    By netchie in forum Forms
    Replies: 5
    Last Post: 03-15-2013, 03:48 PM
  2. Using AutoNumber primary key on sorted column
    By grkatz823 in forum Access
    Replies: 7
    Last Post: 03-04-2013, 03:47 PM
  3. Inner Join on Sorted Columns
    By Nobody in forum Queries
    Replies: 6
    Last Post: 08-24-2010, 03:28 PM
  4. Some values in report did not sorted
    By Akirien in forum Reports
    Replies: 1
    Last Post: 04-14-2010, 11:31 PM
  5. Multiple Query Results Sorted Together
    By Rawb in forum Reports
    Replies: 1
    Last Post: 12-10-2009, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums