Select record in dataset - go to different form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a search form that returns data in a subform in dataset view. The
search results dataset shows 5 fields (summary level). I want to be able to
select a record from the dataset search results and then click a "details"
button to open a new form that will display more information about the
selected record.

I've gotten as far as creating a clone of the recordset so I can select an
individual record. I can't seem to get the rest to work...
 
This example assumes one of the 5 fields in the search form is the primary
key - a Number type field named "ID". Adjust so it uses your actual field
name:

Dim strWhere As String
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenForm "Form2", WhereCondition:=strWhere
 
How are you selecting the record in the subform - by clicking on the
RecordSelector along the left side?

Assuming that you are, you can use the subform's form click event to open
the form. The form's event will open the form that you want to use. Read the
primary key value from the record and provide it to the form being opened
via the WhereCondition argument of DoCmd.OpenForm statement.

Private Sub Form_Click()
DoCmd.OpenForm "FormName", , , "[PrimaryKeyFieldName] = " & _
Me.PrimaryKeyFieldName.Value
End Sub
 
Back
Top