Engr. Matthew
New member
- Local time
- Today, 04:23
- Joined
- Feb 27, 2021
- Messages
- 15
I have a main form with subform that loads different subform dynamically.
the form is working very well and subform is displaying correctly.
I am trying to retrieve the information based on the main form and any loaded subform to generate a report based on OrderID and PatientID.
Here is the situation
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Handler
Dim strReportName As String
Dim ctlSub As Control
' --- 1. Check that ReportToLoad exists ---
If Not TempVars.Exists("ReportToLoad") Then
MsgBox "Missing ReportToLoad variable.", vbExclamation, "Report_Open"
Cancel = True
Exit Sub
End If
strReportName = "Report." & TempVars!ReportToLoad
Debug.Print "Loading subreport:", strReportName
' --- 2. Try to load the subreport ---
Set ctlSub = Me!subCompletedReport
ctlSub.SourceObject = strReportName
' --- 3. Don’t set any links yet (show all data first) ---
Debug.Print "? Subreport loaded successfully."
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Report_Open Error"
Resume Exit_Handler
End Sub
This is the code on the report
Private Sub cmdBtnPreviewReport_Click()
On Error GoTo Err_Handler
Dim lngOrderID As Long
Dim lngPatientID As Long
Dim strTestName As String
Dim strReportName As String
' === 1. Collect main identifiers ===
lngOrderID = Nz(Me!OrderID, 0)
lngPatientID = Nz(Me!PatientID, 0)
strTestName = Nz(Me!TestName, "")
If lngOrderID = 0 Or lngPatientID = 0 Or Len(strTestName) = 0 Then
MsgBox "Missing patient or test information.", vbExclamation
Exit Sub
End If
' === 2. Lookup corresponding report name ===
strReportName = Nz(DLookup("ReportName", "tblTestForms", "TestName='" & strTestName & "'"), "")
If Len(strReportName) = 0 Then
MsgBox "No report found for test: " & strTestName, vbExclamation
Exit Sub
End If
' === 3. Save key values in TempVars ===
TempVars.RemoveAll
TempVars.Add "OrderID", lngOrderID
TempVars.Add "PatientID", lngPatientID
TempVars.Add "TestName", strTestName
TempVars.Add "ReportToLoad", strReportName
' === 4. Open the master container report ===
Debug.Print "Opening rptCompletedTest ? " & strReportName
DoCmd.OpenReport "rptCompletedTest", acViewReport ' ? use acViewReport, not Preview
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "cmdBtnPreviewReport_Click"
Resume Exit_Handler
End Sub
The query parameter look like this
PARAMETERS OrderID Long, PatientID Long;
SELECT [Torch Panel].*
FROM [Torch Panel Test]
WHERE [OrderID] = [OrderID]
AND [PatientID] = [PatientID];
The I run the click button on the main form I go Error 348: can someone help
the form is working very well and subform is displaying correctly.
I am trying to retrieve the information based on the main form and any loaded subform to generate a report based on OrderID and PatientID.
Here is the situation
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Handler
Dim strReportName As String
Dim ctlSub As Control
' --- 1. Check that ReportToLoad exists ---
If Not TempVars.Exists("ReportToLoad") Then
MsgBox "Missing ReportToLoad variable.", vbExclamation, "Report_Open"
Cancel = True
Exit Sub
End If
strReportName = "Report." & TempVars!ReportToLoad
Debug.Print "Loading subreport:", strReportName
' --- 2. Try to load the subreport ---
Set ctlSub = Me!subCompletedReport
ctlSub.SourceObject = strReportName
' --- 3. Don’t set any links yet (show all data first) ---
Debug.Print "? Subreport loaded successfully."
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Report_Open Error"
Resume Exit_Handler
End Sub
This is the code on the report
Private Sub cmdBtnPreviewReport_Click()
On Error GoTo Err_Handler
Dim lngOrderID As Long
Dim lngPatientID As Long
Dim strTestName As String
Dim strReportName As String
' === 1. Collect main identifiers ===
lngOrderID = Nz(Me!OrderID, 0)
lngPatientID = Nz(Me!PatientID, 0)
strTestName = Nz(Me!TestName, "")
If lngOrderID = 0 Or lngPatientID = 0 Or Len(strTestName) = 0 Then
MsgBox "Missing patient or test information.", vbExclamation
Exit Sub
End If
' === 2. Lookup corresponding report name ===
strReportName = Nz(DLookup("ReportName", "tblTestForms", "TestName='" & strTestName & "'"), "")
If Len(strReportName) = 0 Then
MsgBox "No report found for test: " & strTestName, vbExclamation
Exit Sub
End If
' === 3. Save key values in TempVars ===
TempVars.RemoveAll
TempVars.Add "OrderID", lngOrderID
TempVars.Add "PatientID", lngPatientID
TempVars.Add "TestName", strTestName
TempVars.Add "ReportToLoad", strReportName
' === 4. Open the master container report ===
Debug.Print "Opening rptCompletedTest ? " & strReportName
DoCmd.OpenReport "rptCompletedTest", acViewReport ' ? use acViewReport, not Preview
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "cmdBtnPreviewReport_Click"
Resume Exit_Handler
End Sub
The query parameter look like this
PARAMETERS OrderID Long, PatientID Long;
SELECT [Torch Panel].*
FROM [Torch Panel Test]
WHERE [OrderID] = [OrderID]
AND [PatientID] = [PatientID];
The I run the click button on the main form I go Error 348: can someone help