Opening report with VBA code, but opens maximized behind other open forms

JeffBarker

Registered User.
Local time
Today, 13:58
Joined
Dec 7, 2010
Messages
130
I'm trying to open a report from a Button on a form, but when the report opens it hides behind the other forms on-screen, meaning you have to go to Window and then select it to bring it forward.

Here's the code I'm using in the on-click event of the first form:

Code:
Private Sub btnPrint_Click()
On Error GoTo Err_btnPrint_Click
    Dim stDocName As String, vResult As Integer
    Dim vOption As Integer, vNow As String
       
    vOption = opt1
    
    If opt1 = 1 Then stLinkCriteria = "" Else stLinkCriteria = "[ReBadge]= TRUE"
        
    If cmbBadgeType = "Delegate" Then
      DoCmd.OpenReport "rptBadgesDelegates", acViewPreview, , stLinkCriteria
    Else
      DoCmd.OpenReport "rptBadgesAll", acViewPreview, , stLinkCriteria
    End If
 
DoCmd.Close acForm, Me.Name

Any help would be appreciated, cheers.
 
Normally this is behavior that occurs when you have the Modal property of your form set to "Yes".

The way I have handled this in the past is to add code to set the visible property of any open form to "No" when the Report is opened. Then add code to the On Close event of your report that will Restore the maximized condition and reset the visible property of the open form to "Yes".

If you have the possibility of having multiple open forms when the report is opened, you can design your code to itereate through all of your forms and if they are open, set their visible property to No or Yes depending on weather you are opening a report or closing the report.

I don't have a specific example of working with multiple open forms, but that is the general idea.
 
Normally this is behavior that occurs when you have the Modal property of your form set to "Yes".

The way I have handled this in the past is to add code to set the visible property of any open form to "No" when the Report is opened. Then add code to the On Close event of your report that will Restore the maximized condition and reset the visible property of the open form to "Yes".

If you have the possibility of having multiple open forms when the report is opened, you can design your code to itereate through all of your forms and if they are open, set their visible property to No or Yes depending on weather you are opening a report or closing the report.

I don't have a specific example of working with multiple open forms, but that is the general idea.

Hi Mr. B - thanks for this, I'll have a butchers online and see what I can come up with.
 

Users who are viewing this thread

Back
Top Bottom