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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open 2nd Form Filtered on 1st Form criterion

Status
Not open for further replies.

SDS100UK

MIS
Jul 15, 2001
185
GB
Hi,

Acc XP:

I am sure this is simple, but I am simple too and thats the problem!

I have a list of customers with a unique customer id.
I want to open a 2nd separate form which will show only the orders of the customer selected in form 1.

As there are multiple orders for the one customer i figured a filter is the best way to do this.

I really would appreciate someone posting the code i can put onto a button to do this.

The customer ID has to be alphanumeric

Many many thanks in advance

Steven
 
Access can create a command button on a form, which will open another form. The second form can then display records which match the displayed record in the first form.

In Access 2000 and later, you can run a wizard which creates the correct code behind a button for you.

To do this:

Display the first form in Design Mode
Display the toolbox
Make sure the 'Wizard' button in the toolbox is clicked
Create a command button using the wizard
Choose Form Operations from the Categories box
Choose Open Form from the actions box
Click [Next]
Choose the form to open from the list, and click [Next]
On the next screen, choose the required option (show all records, or show matching records), and click [Next]
-- If you choose the matching records option, choose the fields to be matched from the next screen
Choose text or a picture for the button, and click [Next]
Name the button, e.g. btnOpenEmployeesForm, and click [Finish]
________________________________________

Note: If you create a button which displays matching records, then when you click the button:

-- The required form opens
-- This form is filtered to display only matching records (as if you had used the 'filter by form' option)
-- You can view the matching records using the navigation buttons at the bottom left of the form, in the usual way.
________________________________________

Here is some sample code created by Access, to display matching records in the second form:

Code:
Private Sub btnOpenAppUseForm_Click()
On Error GoTo Err_btnOpenAppUseForm_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmSecondForm"
    
    stLinkCriteria = "[CustomerID]=" & Me![CustomerID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_btnOpenAppUseForm_Click:
    Exit Sub

Err_btnOpenAppUseForm_Click:
    MsgBox Err.Description
    Resume Exit_btnOpenAppUseForm_Click
    
End Sub

I hope that this helps.


Bob Stubbs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top