Bring Report To Front Like a real application would (1 Viewer)

JaedenRuiner

Registered User.
Local time
Today, 12:06
Joined
Jun 22, 2005
Messages
154
Okay,
Not to be picky or critical of Access (well maybe a little) but I am having a problem in meeting the customer's desires within the design of my applicaiton. I have several forms which have command buttons that spawn reports in a "Preview" window. Initially I had these reports show as acDialog, which worked, however, they could not "resize" the window that displayed the report. They wanted that ability so I reset my code to open the reports in acWindowNormal. This, however stupidly coded into Access, makes the report window appear behind the current form. Now this would not be a problem, except that you cannot click on the report to bring it to the front/active window.
  • None of my Forms are flagged as "Popup", however, they are displayed using DoCmd.ShowForm with the mode acDialog.
  • I Cannot have the Reports set as Popup = Yes, as this disables the Zoom, OnePage, MultiPage features of the context menu for the reports.
  • I Cannot HIDE the form that spawns the report as I have no idea which of my many forms spawned the report at that time. Different froms pass in different Filter (wherecondition) strings into the report display process so it is highly improbable for me to know which form needs to be "shown" as well as the forms themselves take openarg parameters to know what is going on. perhaps the visible = true/false does not unload the form, but I cannot have the _Load() event triggered a second time.
  • Normal Applications would have a simple concept like:
Code:
public sub ShowReport(reportName as string) 
   DoCmd.SHowReport reportName
   Dim rpt as REport
   set rpt = Application.Reports(reportName)
   rpt.BringToFront
end sub
which would say that no matter what the form is set as the report should be the top active window. Is there any way to achieve this result in Access?
(and I think we know my furthering negative opinion of Access if it cannot)

Thanks
Jaeden "Sifo Dyas" al'Raec Ruiner
 

JaedenRuiner

Registered User.
Local time
Today, 12:06
Joined
Jun 22, 2005
Messages
154
Re: Brint Report To Front Like a real application would

vbaInet, thanks for the prompt reply.

I had atually thought of something like that. I have a module procedure that show's my reports, so from the forms I call: ShowReport(reportName, filterString) and it handles it for me. So what I did was added a Form parameter to the ShowReport, and proceeded to set that form's visible property to false and using the syscmd function to wait for the report to close it then sets the form's visible to true.

however, this does seem to mess with my whole design.

the application has a primary "Main Form". This main form has buttons that access each segment of the application for different form access. There are Operators, Machines, and Locations. From each of these forms you can access the others. Thus:
Main -> Operators -> View Machines show's only that operator's machines.
Main -> Machines -> View Location -> shows the location for that machine.
etc.
The problem is that in my Main form's command button code it goes something like this:
Visible = False
ShowForm formName 'ShowForm is a procedure similar to my ShowReport
Visible = True

thus when my Machines Form is displayed from the Main form, the main form is hidden. If you view the Locations from the Machines form the Locations form pops up as a modal dialog. when you close the locations form, the Machines form is still visible, and then when you close the Machines form the main form becomes visible again.

Using this method that i came up with (which is similar to the suggestion you hads), upon the Machines form being made visible after the report closes, the "modal" aspect of the Machines form ends, and thus the Main form becomes visible again. I don't want this to happen. i want the Form spawned by the Main Form to remain modal until it closes, but while not interfering with the report as it is made visible.
This appears to be a very large design flaw in Access, imo.

Thanks
J"SD"a'RR
 

vbaInet

AWF VIP
Local time
Today, 18:06
Joined
Jan 22, 2010
Messages
26,374
Re: Brint Report To Front Like a real application would

So why don't you make the main form visible before the machine form? It's the sequence that matters here. If you want to know what machine form to make visible, add an extra parameter to your ShowReport command that will pass the name of the form to the report's OpenArgs property.
 

JaedenRuiner

Registered User.
Local time
Today, 12:06
Joined
Jun 22, 2005
Messages
154
Re: Brint Report To Front Like a real application would

So why don't you make the main form visible before the machine form? It's the sequence that matters here. If you want to know what machine form to make visible, add an extra parameter to your ShowReport command that will pass the name of the form to the report's OpenArgs property.

It isn't the sequence, it's the limitation of Access.

I have 5 primary forms. The application starts and the Main form is displayed. it has 4 command buttons for the different sections of the application. Machines, Operators, Locations, and Makes/Models. The first three also spawn reports. When a command button on the main form is clicked, the main form hide's itself, and then displays the subsequent form as a Dialog (modal). Each of those three forms can spawn each other as well. Thus, Machines can open Operators or Locations, Locations can view Operators or Machines, and Operators can view Machines or Locations. Again, each form is display as a Dialog. When the first tier (M, L, O) displays the second tier, they do not hide themselves. so when the Machine form spawns the Location form, the Location form, when closed returns to the machine form. When the machine form is closed, the MOdal sequence is complete and the Main form's command button event continues past the Show command, and makes it's visible again.

Now, when any of the Machine, Operator, or Location forms spawn a report I want this behavior:

The report should display on top and be interactive, allow for multiple levels of zoom, one page, multi page, export or print, and be re-sizable by the user. However, with Access, because a Form is modal (shown with the acDialog window mode), it takes precedence over non-modal windows. thus, showing the report in preview mode with acWindowNormal makes the report display behind the current form, and thus you cannot click it. If during this process you set the Visible property of the form to false, this ENDS THE MODAL SEQUENCE, and the Main form's code continues running as if the form had been closed. If you set the report's window mode to acDialog, it pops up in front of the current modal form, but you cannot select any of the context menu items in Dialog mode. Talk about idiotic catch-22.

The only solution I can see, is to have the Main form loop to check if any other form is open and until they close, remain hidden, at which point it becomes pointless to have any form in Dialog mode, and thus I have to handle all window management instead of Access doing it for me like a normal application. This is a lot of EXTRA work just to reinvent the wheel.

I appreciate the help, but it is simply beyond Access to perform the way I would expect.

J"SD"a'RR
 

JaedenRuiner

Registered User.
Local time
Today, 12:06
Joined
Jun 22, 2005
Messages
154
FOUND IT!!!!

Hah, so it may be a hack, but it works exactly as planned. for some reason the acDialog is completely wonky in the Access architecture, but the Form.Modal property behaves as expected. So, my solution was simple:
Code:
public sub ShowForm(formName as string, optional args as string = "")

   DoCmd.OptenForm formName, acNormal, , , , acWindowNormal, args

   Dim frm as Form
   Set frm = Forms.Item(formName)
   If Not frm is nothing Then
      frm.Modal = True
      While (SysCmd(acSysCmdGetObjectState, acForm, formName) And acObjStateOpen) = acObjStateOpen
         DoEvents
      Wend
   End If

end sub

This code:
  • Blocks execution until the form closes.
  • Sets the form as Modal and thus remains on top as a dialog would.
  • Does not block acWindowNormal report viewers so that viewing a report can be resized and manipulated with context menus.

Thanks for the help, but i finally found the solution that does exactly what I wanted.
Jaeden "Sifo Dyas" al'Raec Ruiner
 

vbaInet

AWF VIP
Local time
Today, 18:06
Joined
Jan 22, 2010
Messages
26,374
Good work Jaeden.

I've seen acDialog behave differently from when you manually set it in the property sheet. Did you have a reason why you didn't set it from there instead?

I know you've got it solved to your satisfaction but if you have time upload a test db and I will try out what I mentioned.
 

Users who are viewing this thread

Top Bottom