Share via

Syntax problem selecting a control in a subform

katzen 40 Reputation points
2026-01-20T23:09:31.8166667+00:00

Once duped by the lure of being allowed to put spaces in control and table names, many times sorry. I will never do it again. I'm doing OK on the logic, but keep breaking down over syntax since doing this.

I have a form "f HT Creates" which has a subform "f Individual Pieces Entry". The subform contains a list of pieces by the artist named in "f HT Creates". Each piece has a unique "Piece ID".

Another form, "f Search Box for IP" creates a dynamic list of individual pieces for ain the collection, with the objective to discover and display the artist information for the piece. I want my user to be able to click on the control in the list corresponding to the Piece ID (named, simply "id") and pull up "f HT Creates" and have it display the artist information in the main form and in the subform the piece with "Piece ID" equal to the one clicked on in "f Search Box". The value of the selected "Piece ID" on form "f Search Box for IP" is translated earlier in the code to be the variable "lngID".

My original version of "f Search Box" does this for the "Artist ID", which is on the parent form "f HT Creates". I cloned it, made the appropriate changes to field names, and successfully used it for another control on the parent form "f HT Creates".

I cannot get it to run in this version, where the field to compare is on the subform. The lines in question are:

    strCriteria = "Form![f HT Creates]![f Individual Pieces Entry].Form![Piece ID] = " & lngID

    rs.FindFirst strCriteria

    If Not rs.NoMatch Then

    DoCmd.OpenForm "f HT Creates", acNormal, , strCriteria, , acDialog

When I run it, Access gives me a run-time error 3070 and tells me it "does not recognize 'Form!f HT Creates!f Individual Pieces Entry.Form!Piece Number' -- without the brackets. When I open the debugger, and look at the present value of strCriteria at the two points, it is also without the brackets. It appears to be a syntax error on my part when defining the control for strCriteria, but cannot figure out what is wrong with my syntax.

Can anyone help, please?

Microsoft 365 and Office | Access | Other | Windows

2 answers

Sort by: Most helpful
  1. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2026-01-20T23:31:12.4566667+00:00

    Where/ how are you defining “rs”?

    Was this answer helpful?


  2. AI answer

    2026-01-20T23:09:49.05+00:00

    It looks like you're encountering a syntax issue when trying to reference a control on a subform in Microsoft Access. The error message indicates that Access is not recognizing the control path correctly. Here are a few suggestions to help you resolve this issue:

    1. Correct Syntax for Subform Reference: When referencing controls on a subform, ensure that you use the correct syntax. The correct way to reference a control on a subform is as follows:
         strCriteria = "[Piece ID] = " & lngID
      
      This assumes that you are already on the parent form and that you have the subform control name correctly set.
    2. Using the Subform Control Name: If you are trying to reference the subform from the main form, make sure you are using the name of the subform control, not the name of the form itself. For example:
         strCriteria = "[f Individual Pieces Entry].[Form]![Piece ID] = " & lngID
      
      This syntax indicates that you are accessing the form object of the subform control.
    3. Debugging the Criteria: You can debug by printing out the strCriteria before using it in rs.FindFirst to ensure that it is formatted correctly. Use:
         Debug.Print strCriteria
      
      This will help you see the exact criteria being passed.
    4. Check for Spaces: Since you mentioned using spaces in control names, ensure that you are enclosing control names with spaces in square brackets. For example:
         strCriteria = "[f HT Creates]![f Individual Pieces Entry].[Form]![Piece ID] = " & lngID
      
    5. Ensure Controls Exist: Double-check that the controls you are referencing actually exist on the forms and subforms as expected. Sometimes, a typo in the control name can lead to this error.

    By following these guidelines, you should be able to resolve the syntax issue and correctly reference the control in your subform.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.