locked
set focus to first record on continuous form... RRS feed

  • Question

  • I have a continuous form.

    When invoked focus is set to the last record.

    I've added : "DoCmd.GoToRecord , , acFirst"  to the Form_Load event, but no such luck.

    Any suggestions?


    Thanks for your help!!

    Saturday, September 2, 2017 10:48 AM

Answers

  • DBguy - got it!

    The issue was that I was programmatically setting a value in a text box.  So, I moved this logic into my query and that seems to have done the trick.  Thanks for pointing me to my other code.

    Deepak and lmb - thanks for weighing in.


    Thanks for your help!!

    • Marked as answer by plynton Monday, September 4, 2017 6:11 PM
    Monday, September 4, 2017 6:11 PM

All replies

  • When invoked focus is set to the last record.

    Hi plynton,

    In normal cases focus is on the first record after opening a continous form.

    You could remove the instruction to go to the last record. But perhaps you only want a different sorting? Then add an ORDER BY clause to the RecordSource of the form.

    Imb.

    Saturday, September 2, 2017 12:02 PM
  • Hi plynton,

    if you want to go to first record if current record is last record in your form then you can use code below.

    Private Sub Form_Current()
    
    Dim rs As Object
     Set rs = Me.RecordsetClone
     If Me.CurrentRecord = rs.RecordCount Then
     DoCmd.GoToRecord , , acFirst
     End If
     
    End Sub

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 4, 2017 2:06 AM
  • Deepak,

    Thanks for the response.

    It seems that my issue is when applying a filter.  Access seems to be randomly picking a record for focus.


    Thanks for your help!!

    Monday, September 4, 2017 1:06 PM
  • Hi,

    How exactly are you applying a filter? If by code, can you show it to us?

    Monday, September 4, 2017 4:25 PM
  •     Me.Filter = "ProductCategory IN ('Candle Ring','Cones & Decor','Garland')" & supFilter
        Me.FilterOn = True
        Me.Requery

    Thanks for your help!!

    Monday, September 4, 2017 4:41 PM
  • Same behavior if I remove the requery

    Thanks for your help!!

    Monday, September 4, 2017 4:46 PM
  • It seems that my issue is when applying a filter.  Access seems to be randomly picking a record for focus.

    Hi plynton,

    The FIRST record can be any record if you don't have the records ordered in the way you expect.

    Does the problem still exists with proper ordering of the recordset?

    Imb.

    Monday, September 4, 2017 4:53 PM
  • Same behavior if I remove the requery

    Thanks for your help!!

    Hi,

    When you apply a filter, the navigation pointer automatically goes to the first record, so a Requery is not necessary.

    If the record pointer is not ending up on the first record, there might be other code moving it? Can you post the complete code beginning with Private Sub up to End Sub? Thanks.

    Monday, September 4, 2017 4:54 PM
  • DBguy - got it!

    The issue was that I was programmatically setting a value in a text box.  So, I moved this logic into my query and that seems to have done the trick.  Thanks for pointing me to my other code.

    Deepak and lmb - thanks for weighing in.


    Thanks for your help!!

    • Marked as answer by plynton Monday, September 4, 2017 6:11 PM
    Monday, September 4, 2017 6:11 PM
  • Hi,

    Congratulations! Glad to hear you got it working. We were all happy to assist. Good luck with your project.

    Monday, September 4, 2017 6:25 PM