Hi,
I am trying to set the focus to a report I am opening.
There is a button I have on a popup modal form that opens a report using DoCmd.OpenReport when clicked and it passes a string for concatonating the query in the report. In the open sub of the report, it uses open args to set the source. The report opens and shows the data, but the problem is I have a form open (acting as a menu to open other forms) and the report opens "behind" this in another tab. I would like to set the focus to the report once its open. How can I do this?
This is my code:
Code:
...code concatonates a string, sArgs, to pass through the open report function...
'If the report is already open, close it.
DoCmd.Close acReport, "Shipped Report", acSaveNo
'Tried both ReportView and Preview
DoCmd.OpenReport "Shipped Report", acViewPreview, , , , sArgs
'Try to set focus to opened report, doesn't seem to work
DoCmd.SelectObject acReport, "Shipped Report"
'Close modal popup for generating report
DoCmd.Close acForm, "Report_OutForCalibration"
Here is the code in the open report sub in the report.
Code:
Private Sub Report_Open(Cancel As Integer)
Dim sQuery As String
sQuery = "SELECT Max(Maintenance_History.Date) AS MaxOfDate, Assets.Asset_ID, Asset_Status_Types.AS_Type_Code, Maintenance_Types.M_Type_Name, [Service Provider].Supplier_Name, Assets.GPCL_Asset_ID, Asset_Types.A_Type_Name, Manufacturer.Supplier_Name, Assets.Model, Assets.Serial_Number" & _
" FROM ((Maintenance_History INNER JOIN ((((GPCL_Asset_Details INNER JOIN Assets ON GPCL_Asset_Details.GAD_Asset_Link = Assets.Asset_ID) INNER JOIN Asset_Types ON Assets.Asset_Type = Asset_Types.A_Type_ID) INNER JOIN Asset_Status_Types ON GPCL_Asset_Details.Status = Asset_Status_Types.AS_Type_ID) INNER JOIN Suppliers AS Manufacturer ON Assets.Manufacturer = Manufacturer.Supplier_ID) ON Maintenance_History.Maintenance_Asset_Link = Assets.Asset_ID) INNER JOIN Maintenance_Types ON Maintenance_History.Maintenance_Type = Maintenance_Types.M_Type_ID) INNER JOIN Suppliers AS [Service Provider] ON Maintenance_History.Maintenance_Provider = [Service Provider].Supplier_ID " & _
" GROUP BY Assets.Asset_ID, Asset_Status_Types.AS_Type_Code, Maintenance_Types.M_Type_Name, [Service Provider].Supplier_Name, Assets.GPCL_Asset_ID, Asset_Types.A_Type_Name, Manufacturer.Supplier_Name, Assets.Model, Assets.Serial_Number " & _
" HAVING (((Asset_Status_Types.AS_Type_Code) Like 'OC' Or (Asset_Status_Types.AS_Type_Code) Like 'OR') AND ((Maintenance_Types.M_Type_Name) Like 'Calibration - Shipped' Or (Maintenance_Types.M_Type_Name) Like 'Repair - Shipped'))"
If CheckIfEmpty(Me.OpenArgs) = False Then
sQuery = sQuery & Me.OpenArgs
End If
sQuery = sQuery & ";"
Me.RecordSource = sQuery
End Sub
I apologize if my code is messy, but any help regarding setting the focus to the report once it has been opened would be greatly appreciated. Thank you in advance.