Results 1 to 3 of 3
  1. #1
    Kirtap is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    22

    Opening a report and setting focus to it

    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.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    if your form is modal or pop up nothing you do will make it open on top of your form. Is either the POPUP or MODAL value set to TRUE in your form properties?

  3. #3
    Kirtap is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    22
    Ah, the Form popup for generating a report was modal. That caused the report to fall behind the other forms that were open. I changed the popup form so its not modal. It works perfect now. Thanks!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Setting the focus on a subform
    By Paul H in forum Forms
    Replies: 3
    Last Post: 01-10-2012, 09:17 AM
  2. Replies: 1
    Last Post: 01-10-2012, 03:44 AM
  3. Replies: 2
    Last Post: 09-12-2011, 11:11 AM
  4. Setting focus on a tabbed form
    By crowegreg in forum Forms
    Replies: 21
    Last Post: 08-27-2011, 09:22 AM
  5. Setting Focus on a Form
    By MFeightner in forum Forms
    Replies: 1
    Last Post: 07-30-2009, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums