A family of Microsoft relational database management systems designed for ease of use.
Where/ how are you defining “rs”?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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?
A family of Microsoft relational database management systems designed for ease of use.
Where/ how are you defining “rs”?
AI answer
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:
strCriteria = "[Piece ID] = " & lngID
This assumes that you are already on the parent form and that you have the subform control name correctly set. strCriteria = "[f Individual Pieces Entry].[Form]![Piece ID] = " & lngID
This syntax indicates that you are accessing the form object of the subform control.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. strCriteria = "[f HT Creates]![f Individual Pieces Entry].[Form]![Piece ID] = " & lngID
By following these guidelines, you should be able to resolve the syntax issue and correctly reference the control in your subform.
References: