Bring report window to the front

  • Thread starter Thread starter Ragnar Midtskogen
  • Start date Start date
R

Ragnar Midtskogen

Hello,

I have an Access 2000 app where I just added a mailing address report.
I open a form to let use enter criteria, then run the report. The report
works fine but it displays briefly, then disappears behind the main menu
window.
I suspect it has something to do with focus and the fact that the main menu
is maximized, but I have not been able to figure out why this happens.

I have tried using a function with some API calls, including
BringWindowToTop&, to bring the report window to the top but it doesn't
work, possibly because the Access main window is an MDI window. The same
function works fine when I use it to bring a Word mail merge document
(Opened from Access) to the top.

I must be possible to do the same thing with the child windows in Access. I
think I did something like this in an app, but can't remember where.

Any help would be appreciated.

Ragnar
 
Ragnar:

A couple of points:

1.) If your form is either opened modally or as a dialog, the report window
can't pop to the front. So look at that first.

2.) You can manipulate moving the window to the front using api calls,
provided the form is not modal or a dialog, by addressing the proper midi
child window. The window class name of an Access report is "OReport". Your
needs to navigate throuigh all the child windows, finding the window by
class name and then validating its the target window by looking at the
window name (i.e the display title of the report). Listed below is some
code that should get you started. It is designed to find the db window and
move it to the bottom if it had popped to the top. You'd need to change the
target window class to OReport from ODb and add code to check the Window
name, but this is how you do it. The api declares and module level vars
have not been included here.
--
SA
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

----------begin code------------

Private Sub atDBBottom(chkVis As Boolean)
'----------------------------------------------------------------
'Purpose: Move the DB window to the bottom of the Window Z order
' to handle issue when reports are printed as secure
' reports where db window is given the focus from selecting
' the report in the db window.
'Accepts: chkVis flag is used to tell the function to either a.) check
whether the db window
' is visible and store that value in a global module variable
b.)
' or to manipulate its position and visibility.
'Returns: Nothing
'----------------------------------------------------------------
On Error GoTo Err_MWC
Dim WinhWnd&, hWndMidi&, hWndTarget&
Dim dwReturn&, ClsNameBuff$, ClsBuffsz%

Const TARGET_WINDOW_MIDI = "MDIClient"
Const TARGET_WINDOW_DB = "ODb"
Const GW_HWNDNEXT = 2
Const GW_CHILD = 5
Const HWND_BOTTOM = 1
Const SWP_NOACTIVATE = &H10
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SW_HIDE = &H0

ClsBuffsz = 32
ClsNameBuff = Space(ClsBuffsz)

WinhWnd = Application.hWndAccessApp
hWndMidi = FindWindowEx(WinhWnd, 0&, TARGET_WINDOW_MIDI, vbNullString)
If hWndMidi = 0 Then
Exit Sub
End If

hWndTarget = GetWindow(hWndMidi, GW_CHILD)
dwReturn = GetClassName(hWndTarget, ClsNameBuff, ClsBuffsz)

If InStr(ClsNameBuff, TARGET_WINDOW_DB) > 0 Then
If chkVis = True Then
boolDbWindowVisible = IsWindowVisible(hWndTarget)
Else
If boolDbWindowVisible = 0 Then
dwReturn = ShowWindow(hWndTarget, SW_HIDE)
Else
Call SetWindowPos(hWndTarget, HWND_BOTTOM, 0, 0, 0, 0,
SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE)
End If
End If
Exit Sub
End If

While hWndTarget > 0
hWndTarget = GetWindow(hWndTarget, GW_HWNDNEXT)
dwReturn = GetClassName(hWndTarget, ClsNameBuff, ClsBuffsz)
If InStr(ClsNameBuff, TARGET_WINDOW_DB) > 0 Then
If chkVis = True Then
boolDbWindowVisible = IsWindowVisible(hWndTarget)
Else
If boolDbWindowVisible = 0 Then
dwReturn = ShowWindow(hWndTarget, SW_HIDE)
Else
Call SetWindowPos(hWndTarget, HWND_BOTTOM, 0, 0, 0, 0,
SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOACTIVATE)
End If
End If
Exit Sub
End If
Wend

Exit_MWC:
Exit Sub
Err_MWC:
Resume Exit_MWC
End Sub
----------------end code----------------------
 
Thank you SA, made my day!

The form is modal, but I was hiding it. But the form was not hidden until
after the report opened. When I moved the code to hide the form before I
call the function that opens the report, the report opens on top!
I thought it would open behind the form, but come to the top when the form
was hidden. Instead it ended up behind the main menu form.
I could alway bring it to the top by manipulating the windows manually with
the Windows menuitem, but the users should not have to do that.
Now I don't need to use your code, but I am glad to have seen it, because
now I understand how to deal with Access MDI and MDI child windows.
My code for dealing with Word was stepping through all windows, looking for
the form letter document. To manipulate the report I would just do the same
thing, but stepping through the MDI child windows.

Ragnar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top