GoToRecord passing a condition

v.bon

New member
Local time
Today, 11:53
Joined
Aug 29, 2017
Messages
7
Is there a way where you can write some code that says:
GoToRecord WHERE PrimaryKey=Variable

This will then change the record displayed in main form.

Any Ideas?
 
Many ways - Assuming your form is bound to the table then try this is one;
Code:
    Dim rs              As Recordset

    If Not IsNull(Me.txtFinder) Then
        Set rs = Me.RecordsetClone
        rs.FindFirst "[YourPrimaryKey] = " & Me.txtFinder
        If Not rs.NoMatch Then
            Me.Bookmark = rs.Bookmark
        End If
        Set rs = Nothing
    End If

This assumes you have an unbounbd text box, probably in the form header, called txtFinder that you will type your PK in. It also assumes your primary key is a number, not text. You could make it a combobox if you only have a limited number of PK numbers you want to bring in.

Put the code in the AfterUpdate event of your txtFinder control.
 
Last edited:
Thank you for your reply. I believe I am on the right track but keep getting the error 'runtime error:3021 No current record' would you know why?
Code:
 Private Sub Form_Current()
    Dim RecordValue As String
    Dim rs As Object
    
    If Not IsNull(Me.Company_Name) Then
        RecordValue = Me.Company_Name
        If Forms!Company.[Company Name] <> RecordValue Then
            Set rs = Forms!Company.RecordsetClone
            rs.FindFirst "[Company Name]= '" & RecordValue & "'"
            If rs.NoMatch Then
            MsgBox "NO MATCH"
        Else
            Forms!Company.Bookmark = rs.Bookmark
        End If
        Set rs = Nothing
    End If
    End If
    
    End Sub
 

Users who are viewing this thread

Back
Top Bottom