Loading...
Saturday, March 1, 2014

How to go back to current record when doing Requery


Sub openDetailForm(p_frm As Form, p_frm_detail_name, Optional p_ctrl_col = Null, Optional p_key_col = Null, Optional p_refresh = True, Optional p_win_mode As AcWindowMode = acDialog)

    Dim rs As Object
    Dim v_id
    v_id = p_ctrl_col
    
    DoCmd.OpenForm p_frm_detail_name, , , IIf(IsNull(p_ctrl_col), "1=0", p_key_col & " = " & p_ctrl_col), , p_win_mode, IIf(IsNull(p_ctrl_col), Null, p_ctrl_col)
    
    If p_refresh Then
        p_frm.Requery
             
         ' Find the record that matches the control.
        Set rs = p_frm.Recordset.Clone
        
        rs.FindFirst p_key_col & " = " & Str(Nz(v_id, 0))
        
        If rs.EOF = False Then
            p_frm.Bookmark = rs.Bookmark
        Else
            DoCmd.GoToRecord acActiveDataObject, , acLast
        End If
    End If
End Sub

0 comments:

Post a Comment

 
TOP