closing report

T

Ted

i have a form which takes information which a user enters onto a form
(startdate and stopdate)
which is passed along to an onclickevent behind a 'preview report' cmd
button i created on it. i also have a 'close report' cmd button i added to
the the same form. i notice that there are min/max/close buttons in the upper
right hand corner of the
viewer with which the report is displayed on screen. i would like to either
a) remove the 'close' ('X') one from the trio displayed OR b) find some way
to prevent the report's closing when that 'X' button is clicked while the
pop-up form is open. in short, i would just prefer to delegate the task of
closing the report exclusively to the 'close report' button i created on the
form itself
 
S

SA

Ted:

In Access 2002 and greater have report properties that control the close
button (also control box). Previous versions do not. However, you can use
Windows Api calls to do this. Here's how.

1.) In a general module, paste in this code below starting in the general
section
2.) In your report's On open event add code like:

Call EnableCtrlBox(False, Me.hWnd)

Hope that helps
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

'------------begin general module code----------
Private Declare Function GetSystemMenu Lib "user32" (ByVal _
hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" _
(ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, ByVal wEnable As
Long) As _
Long

Function EnableCtrlBox(boolEnable As Boolean, _
Optional ByVal lnghWndTarget As Long = 0) As Long
'-----------------------------------------
'Used to disable the close button on a form or report
'Accepts: boolEnable: True = Enable, False = Disabled.
' lnghWnd: Option handle for a form or report
' default is Access main window
'-----------------------------------------
Dim lngReturnVal As Long
Dim hWndMenu As Long
Dim lngAction As Long
Const MF_BYCOMMAND = &H0&: Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&: Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&
Debug.Print lnghWndTarget
If lnghWndTarget = 0 Then
lnghWndTarget = Application.hWndAccessApp
End If

hWndMenu = GetSystemMenu(lnghWndTarget, False)
lngReturnVal = 0

If hWndMenu <> 0 Then
If boolEnable Then
lngAction = MF_BYCOMMAND Or MF_ENABLED
Else
lngAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
End If
lngReturnVal = EnableMenuItem(hWndMenu, SC_CLOSE, lngAction)
End If
EnableCtrlBox = lngReturnVal

End Function
 
T

Ted

steve,

i am so totally sure your code's going to get this to the point i'm striving
for, i'm not even going to test it before giving you a "gold star"!!

many thanks,

-ted
 
T

Ted

Hi Steve,

As I 'predicted' it works great....there's a small fly in this however, and
that is that when I click on the 'Maximize' button (it and the 'Minimize'
button are available when the report pre-viewer opens initially), the 'Close'
button becomes re-available to the user; when I next proceed to click the
'Restore' button on the window, the 'Close' button gets stippled out once
more. Is this expected?
 

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

Top