Open a form to a record selected in a subform

978 views Asked by At

I want to open a form to the record selected in the subform of a different form. I've tried following what I’ve seen in other posts about this, but I still can't get it to work. I think I'm just missing some very basic detail but this is my first Access database and I can't figure out what it is. Thanks in advance for your assistance.

Details:

  • F_Detail - (This is a Single Form containing details on a project.)
  • F_List - (This is a Single Form containing a subform and a button.)
  • subF_List - (This is the subform contained in F_List. This subform is in Datasheet view)
  • Project_ID - (This is the primary key contained in subF_List and in F_Detail. It is the common criteria between the two. It is Short Text type.)

subF_List displays row after row of projects. F_Detail displays details about a single project at a time. From F_List I want to select a row in subF_List and then click the button to open F_Detail, and F_Detail will be displaying details of the project whose row was selected in subF_List when I pressed the button.

What I Have for the Button: On Click > Event Procedure

    Private Sub ProjectDetailButton_Click()

    DoCmd.OpenForm "F_Detail",,,"Project_ID = " & Me.Project_ID

    End Sub

Upon clicking the button, I get an error saying, "Compile error: Method or data member not found" and it highlights the .Project_ID at the end of my code.

I don't know what I'm doing wrong and would appreciate any help you can lend. Please let me know if I've left out any needed detail.

1

There are 1 answers

0
June7 On

Use apostrophe delimiters for text field parameters. Use # for date/time, nothing for number.

"Project_ID = '" & Me.Project_ID & "'"

Me is alias for form or report the code is behind. To reference a field in its RecordSource:

Me!Project_ID

Code on main form referencing field on subform must reference through subform container control. I always name container different from object it holds, such as ctrProjects:

Me.ctrProjects!Project_ID

I name controls different from fields they are bound to, such as tbxProject:

Me.ctrProjects.Form.tbxProject