View Full Version : Linking 2 Forms


Lee Stapleton
11-07-2000, 02:18 AM
I have to forms, 1 main input form and a datasheet form that displays all my records. I need to be able to double click on anyone of these records and it open up the 1st form for that selected record.

Rich@ITTC
11-07-2000, 05:18 AM
Hi Lee

You need to add the following code to your "Datasheet" or Form 2 (for whichever field, or all fields, that the user can double-click on).

Private Sub txtYourField_DblClick(Cancel As Integer)
On Error GoTo Err_txtYourField_DblClick

Dim stDocName As String
Dim LinkCriteria As String

stDocName = "frmYourForm1"
LinkCriteria = "[YourForeignKey] = Forms!frmYourForm2![YourPrimaryKey]"
DoCmd.OpenForm stDocName, , , LinkCriteria

Exit_txtYourField_DblClick:
Exit Sub

Err_txtYourField_DblClick:
MsgBox Err.Description
Resume Exit_txtYourField_DblClick
End Sub

The ForiegnKey in Form2 is the same key/value as your Primary Key in Form1 (i.e. it is the shared field used to establish the Relationship between the two tables).

HTH

Rich

[This message has been edited by Rich@ITTC (edited 11-07-2000).]