Results 1 to 8 of 8
  1. #1
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211

    Identify First or Last Visible SubForm Record

    I have a main form and a Subform. The Subform contains 50 or more records in continuous-form display. It's only tall enough to show 9 items. Of course the Subform can be scrolled to show any 9 records, without actually selecting a record.



    Is there a way to identify the first visible Subform record? Would also be nice to know how many records are visible, so therefore I would also be able to calculate the last visible record. This is just a nice-to-have, and I would be happy with the first record only. If I had a "record number" of the first visible Subform record, I could calculate the last visible record myself, knowing the detail height.

    Sometimes I do some operations in the main form that causes the Subform records to be modified. So I requery the subform. Of course this makes the subform start again at the top. More desirable is to have the Subform showing prior first visible item.

    I would like to know the value of the first visible record, but this is complicated by the fact that different Subforms have different data. Therefore, I'd be satisfied with finding the bookmark or record number of the first visible record, or something else that identifies the actual record position in the subform.

    I can't use Form_Current, because I may not have selected a record. I can't necessarily use the underlying recordset that the Subform is bound to, because the recordset may be in one order, and the Subform may have it's OrderBy set, so it's displaying in a different order.

    I'm thinking maybe some Windows API function may help here. I'm comfortable working with the API.

    Thanks for any help...

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    A lot of room for interpretation wrt your questions, I think.
    Is there a way to identify the first visible Subform record?
    ID how?
    I would also be able to calculate the last visible record
    Calculate a record?? What does that mean? Does any of that have to do with you selecting a record and looking at the built in record navigation controls, which tell you that record is #x out of #n?

    So I requery the subform. Of course this makes the subform start again at the top.
    Research how to clone the form recordset, set a bookmark to the current record, then after requerying, make the bookmarked record the current record.
    I would like to know the value of the first visible record
    Records don't have values - fields have values.
    I'd be satisfied with finding the bookmark or record number of the first visible record
    Click on a field in the record or use the record selectors if you show them.
    the recordset may be in one order, and the Subform may have it's OrderBy set, so it's displaying in a different order.
    That makes no sense to me. A form recordset has an order. It is either ascending (by default or by choice), or descending by choice. AFAIK, a recordset cannot have one order while a form has another order.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Requery the recordset and not the form. Then the record pointer does not change.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Google Stephen lebans get/set scrollpos functions

  5. #5
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Micron View Post
    A lot of room for interpretation wrt your questions, I think.
    ID how?
    Calculate a record?? What does that mean? Does any of that have to do with you selecting a record and looking at the built in record navigation controls, which tell you that record is #x out of #n?

    Research how to clone the form recordset, set a bookmark to the current record, then after requerying, make the bookmarked record the current record.
    Records don't have values - fields have values.
    Click on a field in the record or use the record selectors if you show them.
    That makes no sense to me. A form recordset has an order. It is either ascending (by default or by choice), or descending by choice. AFAIK, a recordset cannot have one order while a form has another order.
    This seemed so clear to me when I was posting those questions. I guess I totally failed to get my questions across clearly.
    I will differ with you on your last comment. If a form's recordset is a select query with an order by, the form can still have an order by and order by on load which changes that order.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Subform may have it's OrderBy set
    Yup, totally missed those keywords. I blame having notepad open on the top of the browser trying to correlate questions with answers instead of continually swapping windows. It's all I've got for an excuse.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Welshgasman View Post
    Requery the recordset and not the form. Then the record pointer does not change.
    Thanks Welshgasman. That totally worked. Funny how you can work with Access for years and years, and then learn something so simple yet fundamental like that...

  8. #8
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by CJ_London View Post
    Google Stephen lebans get/set scrollpos functions
    Thanks for the reply, CJ_London. I've used Stephen Lebans' code before, and updated some of it to work with Access 2016. Turns out I don't need anything so complex. Welshgasman's tip worked like a charm. Thanks anyway...

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

Similar Threads

  1. Replies: 18
    Last Post: 05-26-2020, 06:46 PM
  2. Replies: 3
    Last Post: 05-02-2018, 11:37 AM
  3. Replies: 3
    Last Post: 06-29-2017, 03:02 PM
  4. Replies: 5
    Last Post: 04-06-2012, 10:59 AM
  5. Replies: 2
    Last Post: 01-06-2011, 04:38 AM

Tags for this Thread

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