Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open form to specific record (without filter)

Status
Not open for further replies.

Ebes1099

Technical User
Jul 8, 2009
156
US
I'm trying to open another form from a button on a different form to the matching record on the open form and have it not be filtered to just that one record. Right now I have it opening to the correct record but it's filtered to just that one record and you can't scroll left or right to get to the next record.

On my search in the new form it works great, I use a recordset to set a bookmark and when you search for a record it brings you right to it, but then you can still scroll left and right to get to the nearby records.

I want to be able to do this when I open the form. On my first form I have a field called "CodeNumber" and on the second form I have the matching field called "Code". Can I do this?
 
are you opening the form dialog? The reason I ask will determine how you do this.
If dialog the code execution in the calling form stops at the point you open the dialog form. Therefore from the calling form you cannot move to the correct record. You would have to pass the ID in the open args and have the dialog form use that in the load event.

If not dialog then the calling form can move the pop up to the correct record.
 
Originally it was set up using a button and the "wizard" for opening a new form with a button click.

Code:
Private Sub CodeRuleOpen_Click()
On Error GoTo Err_CodeRuleOpen_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Code_Rules"
    
    stLinkCriteria = "[Code]=" & "'" & Me![CodeNumber] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_CodeRuleOpen_Click:
    Exit Sub

Err_CodeRuleOpen_Click:
    MsgBox Err.Description
    Resume Exit_CodeRuleOpen_Click
    
End Sub
 
If using that code, then you are not opening the form dialog and you can control code execution from the calling form. Untested, Something like

Code:
Private Sub CodeRuleOpen_Click()
On Error GoTo Err_CodeRuleOpen_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    dim rs as dao.recordset
    dim frm as access.form

    stDocName = "Code_Rules"
    stLinkCriteria = "[Code]=" & "'" & Me![CodeNumber] & "'"
    DoCmd.OpenForm stDocName
   
    set frm = forms(stDocName)
    set rs = frm.recordset
    rs.findfirst stLinkCriteria    

Exit_CodeRuleOpen_Click:
    Exit Sub

Err_CodeRuleOpen_Click:
    MsgBox Err.Description
    Resume Exit_CodeRuleOpen_Click
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top