Why is the Form Printing?? Instead of the Report? (1 Viewer)

Rudurk

New member
Local time
Today, 08:12
Joined
Jul 14, 2014
Messages
8
Hi,

I have a problem. My Main Form is a Popup Window with print button for other subforms. So I have it set so when the Report opens it hides the Main Form, and I use the
Code:
DoCmd.SelectObject acReport, Reports(0).Name, True
do get focus to Report, and I run a loop just to make sure it does actually have focus and the Main Form does not have focus.

On my PC It works great it prints the report every single time, but when my colleagues are using it... it prints the Main Form instead of the report. I don't get why it would work on my PC, but not work on someone elses?

I don't quite get it..

Code:
Public Sub FocusOnReport()
Dim intState As Integer
    Dim intCurrentType As Integer
    Dim strCurrentName As String

    intCurrentType = Application.CurrentObjectType
    strCurrentName = Application.CurrentObjectName
        DoCmd.SelectObject acReport, Reports(0).Name, True
        Debug.Print "Before Loop " & strCurrentName & " - " & intCurrentType
        Dim cntLoop As Integer: cntLoop = 0
    Do Until intCurrentType = acReport
        DoCmd.SelectObject acReport, Reports(0).Name, True
            intCurrentType = Application.CurrentObjectType
            strCurrentName = Application.CurrentObjectName
        cntLoop = cntLoop + 1
        If cntLoop > 10 Then
            Exit Do
        End If
        Debug.Print "Looped " & cntLoop & " times = " & strCurrentName & " - " & intCurrentType
    Loop
End Sub

Public Function rptMinimize(Optional FormName As Variant) ' used in report load event. Minimizes MainMenu
On Error GoTo Exit_Sub
    If (Screen.Application.Reports.Count > 0) Then
        CloseHiddenTimerForms        
        Forms!MainMenu.Visible = False
            FocusOnReport
        If Not IsMissing(FormName) Then
            Dim Frm As Form: Set Frm = Forms(FormName)
            Frm.Visible = False
        End If        
        FocusOnReport
        DoCmd.Maximize
        Debug.Print Application.CurrentObjectType
    End If
    Exit Function
Retry_Sub:
    CloseHiddenTimerForms
    Forms!MainMenu.Visible = False
    FocusOnReport
    DoCmd.Maximize
    Exit Function
Exit_Sub:
        If Not err.Number = 2457 Then
            GoTo Retry_Sub
        End If
    Debug.Print ("Report Minimize: " & err.Number & err.Description)
        Debug.Print Application.CurrentObjectType
    Exit Function
End Function

How can I make sure it prints the report and not the MainMenu
 

JHB

Have been here a while
Local time
Today, 09:12
Joined
Jun 17, 2012
Messages
7,732
Why not use the DoCmd.OpenReport for printing the report?
 

Rudurk

New member
Local time
Today, 08:12
Joined
Jul 14, 2014
Messages
8
Why not use the DoCmd.OpenReport for printing the report?

Sorry for the late reply.. I am not actually sure what you mean?

I do open the report using DoCmd.OpenReport When the report opens the OnLoad event fires "rptMinimize", which hides the MainMenu so that report can actually be seen...
then it goes on to close some Hidden Timer Forms (Used to log off users remotely...
and gets focus to report..

So I am not sure why then is it still printing MainMenu (It does not have a timer on it soo there is no way its getting focus on its own).. and this only happens on other peoples PC's not mine.. my pc it works correctly every single time, but on others it works then it won't its unpredictable don't really understand why it is like that...

If I were to guess it's because OnLoad event isn't the best option to get focus to report. I am not sure what would be a better way? Right now I am using a custom shortcut to all users to print the report by right clicking and choosing print (Which works, but all the users are used to click on the print button in the ribbon. So want to sort it out, but not sure what I can do. I think i need a way to switch focus to report after it can completely loaded... I wish there was a after load event in Access :( )
 

JHB

Have been here a while
Local time
Today, 09:12
Joined
Jun 17, 2012
Messages
7,732
I mean, why are you not sending the report direct to the printer using DoCmd.OpenReport?
Else minimize the Main form before opening the report, and in the close event for the report set focus back to the main form and restore it.

In the click event for the print button on the form:
Code:
  DoCmd.Minimize
  DoCmd.OpenReport "YourReportName", acViewPreview
In the reports close event!
Code:
Private Sub Report_Close()
 Forms![YourMainFormName].SetFocus
 DoCmd.Restore
End Sub
 

Rudurk

New member
Local time
Today, 08:12
Joined
Jul 14, 2014
Messages
8
I mean, why are you not sending the report direct to the printer using DoCmd.OpenReport?
Else minimize the Main form before opening the report, and in the close event for the report set focus back to the main form and restore it.

In the click event for the print button on the form:
Code:
  DoCmd.Minimize
  DoCmd.OpenReport "YourReportName", acViewPreview
In the reports close event!
Code:
Private Sub Report_Close()
 Forms![YourMainFormName].SetFocus
 DoCmd.Restore
End Sub

The reason I don't want to send the report directly to print is, because my users like to look at how the report is going to look like (e.g. they read the plan they have written down in print preview then go back and make changes as necessary or to check if it has gone over a page or not)

Would minimizing the MainMenu before calling the report help? .. There are literally hundred of reports and hundreds of forms with print buttons.. it would be a pain to write down code for them all (Which is why i choose to just make a function that does everything.), but if it really is the problem I wouldn't really mind doing that.

Still confused as to why it works on my pc everytime (Not a single time will it print Main Menu), but not on others (it will work its not that it won't work at all) when it starts printing MainMenu if the user exits access completely, and goes back on it.. it will print the report for the remainder of that session >_<.

Edit: Main reason for not direct printing would be... that each room has at least one printer.. and the staff move around every time.. so they change the default sometimes.. and direct printing would be annoying also might be a confidentiality problem if it prints the report in another office.. it's patient sensitive information so not everyone is allowed to see it.
 
Last edited:

Users who are viewing this thread

Top Bottom