Example of using Visual Basic to display related records when you move between records

When you move between supplier records on a Suppliers form, you might want to see the products each supplier carries in a Products form. In the Form_Current event procedure of the Suppliers form, set the FilterOn and Filter properties of the Products form:

Private Sub Form_Current()

    ' Declare and set a variable to store the WHERE 
    ' clause that describes the records you want to 
    ' display.
    Dim strCond As String
    strCond = "SupplierID = Forms!Suppliers!SupplierID"

    ' Use the IsLoaded function from the Northwind 
    ' sample database to check whether the Products 
    ' form is open, then set the properties.
    If IsLoaded("Products") Then
        Forms![Products].FilterOn = True
        Forms![Products].Filter = strCond
    End If

End Sub