Results 1 to 4 of 4
  1. #1
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119

    Set focus on specific record on continuous form


    Hi guys,
    i have a continuous form which display a list of all available records. AllowEdits and AllowDataEntry are set to false on the contiuous form.
    Then we have a button CmdViewDetails next to each record on the continuous form.
    Upon clicking that CmdViewDetails button, a new form pops up in modal mode, allowing the user to see details of the record.
    Now when the user edits the record on the new form, i want the focus on the continuous form to remain on the currently edited record.

    i have the following code, placed on the AfterUpdate Event of the new form.

    Code:
    Dim RecPosition As LongRecPosition = Me.CurrentRecord
    
    
    [Forms]!
    [ListStockInventories].Form.Requery ' we requery the continuous form to reflect changes
    [Forms]!
    [ListStockInventories].Form.InvID_PK.SetFocus
    [Forms]!
    [ListStockInventories].Form.Recordset.Move RecPosition ' I want to set the focus on the currently edited record
    the above code works, but not as expected. Instead of pointing to the actual record, it sets the focus to the previously edited record.

    any help would be appreciated.
    Thanks,

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ezybusy is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2015
    Posts
    119
    Awesome!!!
    Thank you pbaldy
    Exactly what i needed.
    Anyone following the same logic like me (set focus on current record on subform) , below is the way i did it:

    Code:
    Private Sub SetFocusOnCurrentRec()Dim lngPK As Integer
    lngPK = Me.InvID_PK
    [Forms]!
    [ListStockInventories].Form.Requery
    With [Forms]!
    [ListStockInventories].Form.RecordsetClone
      .FindFirst "InvID_PK = " & lngPK
      If .NoMatch Then
        MsgBox "Record not found!", vbCritical
      Else
        [Forms]!
    [ListStockInventories].Bookmark = .Bookmark
      End If
    End With
    End Sub
    Then in the afterupdate event of the record editing form you call it:

    Code:
    Call SetFocusOnCurrentRec
    NOTE: if you open the editing form under other circumstances (not only from the continuous form) then, you may consider checking if the continuous form is opened, in order to avoid any error. something like the following:

    Code:
    If CurrentProject.AllForms("yourcontinuousformname").IsLoaded Then        
    Call SetFocusOnCurrentRec
    End If
    i haven't done the checking though, since i don't need it. But i believe it makes sense.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 17
    Last Post: 02-28-2017, 02:12 PM
  2. Replies: 3
    Last Post: 11-28-2016, 03:17 PM
  3. Close one form open another and set focus to a specific field
    By Derrick T. Davidson in forum Programming
    Replies: 12
    Last Post: 08-01-2014, 05:16 AM
  4. Replies: 2
    Last Post: 11-01-2013, 09:57 AM
  5. HELP! Set Focus to Continuous Sub Form Field
    By asmith78 in forum Programming
    Replies: 1
    Last Post: 09-09-2011, 02:27 PM

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