0

I am developing a search form / report builder in Access 2007 called frmSearch. The existing search form works well, showing its results in a subform of a tabcontrol. Then I can click a button to show a report of all tests, which works fine. I want to modify the code to show a report for a single fldTestsID, but am stuck with the Form/Subform/Control path syntax.

There are two tabs: tabResultsTabular shows a subform frmResultsTabular as a query-like list of row. tabResultsRecord shows a subform frmResultsRecords, showing a single record. The report is rpt_TestDatasetExposureEffects. The report's underlying query is q_TestDatasetExposureEffect containing a field called fldTestsID.

So, the path is frmSearch to tabResultsRecord containing button cmdQAReportResults to frmResultsRecords to fldTestsID.

I see that that are other posts for the same error, but did not get them to work. The Access 2007 docs on DoCmd.OpenReport do not mention this specific instance.

Here is the code of the cmdQAReportResults click event including the options I have tried. It fails on the line strRptWhere =. The DoCmd.OpenReport syntax is working based on the Access 2007 docs.

Private Sub cmdQAReportResults_Click()
    doQAReport
End Sub

Private Sub doQAReport()
'On Error GoTo Err_doQAReport 'comment during debugging
   Dim stDocName As String ' report name
'   Dim strRptSQL As String ' report SQL String
   Dim strRptWhere As String ' report WHERE clause

   stDocName = "rpt_TestDatasetExposureEffects"
    'Override the recordsource to match the current record TestsID
'   strRptSQL = "SELECT * FROM q_TestDatasetExposureEffects WHERE fldTestsID = " & fldTestsID
'   DoCmd.OpenReport stDocName, acPreview
    strRptWhere = "0 = 0"
    strRptWhere = "fldTestsID = " & Me.Form![tabResultsRecord].fldTestsID.Value 'error 468
'    other attempts follow
'    strRptWhere = "fldTestsID = " & Forms("frmSearch").Controls("tabResultsRecord").Form.Controls("frmResultsRecords").Form.Controls("fldTestsID").Value
'    strRptWhere = "fldTestsID = " & Me.Form.fldTestsID 'error 2465

   DoCmd.OpenReport stDocName, acPreview, , strRptWhere
'    Reports("rpt_TestDatasetExposureEffects").RecordSource = strRptSQL


Exit_doQAReport:
    Exit Sub

Err_doQAReport:
    MsgBox Err.Description
    Resume Exit_doQAReport

End Sub

1 Answer 1

1

The correct syntax is:

Forms(<Parent Form>).<control container for subform>.form.<control>

In your case this might be:

Forms("frmSearch").frmResultsRecords.Form.fldTestsID

frmResultsRecords is the name of the subform, but is it also the name of the subform's container?

If not, replace it with the name of the control on the main form containing the subform.

Sign up to request clarification or add additional context in comments.

4 Comments

I am getting the same error 438 on this line. strRptWhere = "fldTestsID = " & Forms("frmSearch").Form.frmResultsRecords.fldTestsID When I click on the subform's border and F4 to show properties, it says the item name is frmResultsRecords. The form name in the object viewer is also frmResultsRecords.
Is the name of the control fldTestID or is that the name of the field?
I just noticed that in my example I put Form in the wrong place, it did not match the syntax above it, so I have fixed that. Try changing that.
Yes, That worked! Thank you. The text field containing the key value is fldTestsID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.