472,127 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Access 2007 Runtime Error When Clicking Access Close Button

I am continuing to develop an Access 2007 application which was
originally converted from Access 2003. In Access 2003 I was able to
disable the Access Close button in the top righthand corner of the
screen. I have been unable to find any way to disable this button in
Access 2007 and subsequently I have been forced to find ways to detect
and handle the situations after the Access Close button has been
clicked.

I have been largely successful, but have encountered once situation
for which I am rapidly running out of ideas.

I have a form which contains a command button. The command button
opens a report in preview mode. If I click on the Access Close button
while the report is displayed and the command button's OnClick event
is still running, then control is passed to the report's OnUnload
event and I am able to handle the situation. This is only true when
the application is running as an .accdb database.

However, if I rename the database to .accdr and repeat the test, as
soon as I click on the Access Close button the application displays
the message "Execution of this application has stopped due to a run-
time error.".

I have since modified the application so that the command button's
OnClick event is closed as soon as the report is displayed. In this
scenario the .accdr application does not display the error message
when I click on the Access Close button and successfully passes
control to the report's OnUnload event.

Unfortunately, the second scenario was only created as part of my
ongoing research into the problem. In the real world I want to leave
the command button's OnClick event active so I can perform further
processing once the report has been closed.

I guess I need to understand exactly what happens when the Access
Close button is clicked. I'm aware that all global variables are lost
- and I can handle that situation. Any input or ideas would be most
welcome - particularly a way to disable the Access Close button,
which
would solve all my problems!

Thank you, Tony.
Oct 7 '08 #1
5 5727
ARC
I had trouble with errors when the user would click the top right x to exit
the program as well. I ended up putting message boxes in all the form events
that I had coded to see what was going on. Strangely enough, events fire
that you think would have no business firing when closing the objects and
application. For example, if you have FormCustomers open, and they click the
top-right x, you'll be surprised to see things firing like
FormCustomers_Open or FormCustomers_Load. Things that really should have no
business firing seem to fire (I wouldn't think open or load events would
fire when closing down, would you?).

Hopefully the trick with putting message boxes on all the events of the form
in question (or even report) will help. Once you see which events are
firing, you can check the code on the events and possibly add some "On
error resume next's" or something like:

on error goto ErrRtn

'
'
'
ErrRtn:
exit sub
end sub

"Tony" <to*********@lineone.netwrote in message
news:60**********************************@c36g2000 prc.googlegroups.com...
>I am continuing to develop an Access 2007 application which was
originally converted from Access 2003. In Access 2003 I was able to
disable the Access Close button in the top righthand corner of the
screen. I have been unable to find any way to disable this button in
Access 2007 and subsequently I have been forced to find ways to detect
and handle the situations after the Access Close button has been
clicked.

I have been largely successful, but have encountered once situation
for which I am rapidly running out of ideas.

I have a form which contains a command button. The command button
opens a report in preview mode. If I click on the Access Close button
while the report is displayed and the command button's OnClick event
is still running, then control is passed to the report's OnUnload
event and I am able to handle the situation. This is only true when
the application is running as an .accdb database.

However, if I rename the database to .accdr and repeat the test, as
soon as I click on the Access Close button the application displays
the message "Execution of this application has stopped due to a run-
time error.".

I have since modified the application so that the command button's
OnClick event is closed as soon as the report is displayed. In this
scenario the .accdr application does not display the error message
when I click on the Access Close button and successfully passes
control to the report's OnUnload event.

Unfortunately, the second scenario was only created as part of my
ongoing research into the problem. In the real world I want to leave
the command button's OnClick event active so I can perform further
processing once the report has been closed.

I guess I need to understand exactly what happens when the Access
Close button is clicked. I'm aware that all global variables are lost
- and I can handle that situation. Any input or ideas would be most
welcome - particularly a way to disable the Access Close button,
which
would solve all my problems!

Thank you, Tony.
Oct 7 '08 #2
I don't know whether this will work for you, but it does for me even with
A2007 runtime.

Here one from ms

http://support.microsoft.com/kb/245746

and here a post from Terry Kreft.

Paste the following code into a module, then call it with
Call Buttons(false)

To turn them off and
Call Buttons(True)

to turn them on

' ********** Code Start *************
Option Explicit

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_SYSMENU = &H80000
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Public Const SWP_FRAMECHANGED = &H20

Private Declare Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function SetWindowPos _
Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
' **************************************************
'

Function AccessTitleBar(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long
Dim wFlags As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE
wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or WS_CAPTION)
Else
dwNewLong = (dwLong And Not WS_CAPTION)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function
Function Buttons(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE

Const wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE
Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or FLAGS_COMBI)
Else
dwNewLong = (dwLong And Not FLAGS_COMBI)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function
' ********** Code End *************
--
Terry Kreft
MVP Microsoft Access
Tony wrote:
>I am continuing to develop an Access 2007 application which was
originally converted from Access 2003. In Access 2003 I was able to
disable the Access Close button in the top righthand corner of the
screen. I have been unable to find any way to disable this button in
Access 2007 and subsequently I have been forced to find ways to detect
and handle the situations after the Access Close button has been
clicked.

I have been largely successful, but have encountered once situation
for which I am rapidly running out of ideas.

I have a form which contains a command button. The command button
opens a report in preview mode. If I click on the Access Close button
while the report is displayed and the command button's OnClick event
is still running, then control is passed to the report's OnUnload
event and I am able to handle the situation. This is only true when
the application is running as an .accdb database.

However, if I rename the database to .accdr and repeat the test, as
soon as I click on the Access Close button the application displays
the message "Execution of this application has stopped due to a run-
time error.".

I have since modified the application so that the command button's
OnClick event is closed as soon as the report is displayed. In this
scenario the .accdr application does not display the error message
when I click on the Access Close button and successfully passes
control to the report's OnUnload event.

Unfortunately, the second scenario was only created as part of my
ongoing research into the problem. In the real world I want to leave
the command button's OnClick event active so I can perform further
processing once the report has been closed.

I guess I need to understand exactly what happens when the Access
Close button is clicked. I'm aware that all global variables are lost
- and I can handle that situation. Any input or ideas would be most
welcome - particularly a way to disable the Access Close button,
which
would solve all my problems!

Thank you, Tony.
--
Please Rate the posting if helps you

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200810/1

Oct 8 '08 #3
On 8 Oct, 08:17, "AccessVandal via AccessMonster.com" <u18947@uwe>
wrote:
I don't know whether this will work for you, but it does for me even with
A2007 runtime.

Here one from ms

http://support.microsoft.com/kb/245746

and here a post from Terry Kreft.

Paste the following code into a module, then call it with
Call Buttons(false)

To turn them off and
Call Buttons(True)

to turn them on

' ********** Code Start *************
Option Explicit

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_SYSMENU = &H80000

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Public Const SWP_FRAMECHANGED = &H20

Private Declare Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Private Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function SetWindowPos _
Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
' **************************************************
'

Function AccessTitleBar(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long
Dim wFlags As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE
wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or WS_CAPTION)
Else
dwNewLong = (dwLong And Not WS_CAPTION)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function

Function Buttons(Show As Boolean) As Long
Dim hwnd As Long
Dim nIndex As Long
Dim dwNewLong As Long
Dim dwLong As Long

hwnd = hWndAccessApp
nIndex = GWL_STYLE

Const wFlags = SWP_NOSIZE + SWP_NOZORDER + SWP_FRAMECHANGED + SWP_NOMOVE
Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU

dwLong = GetWindowLong(hwnd, nIndex)

If Show Then
dwNewLong = (dwLong Or FLAGS_COMBI)
Else
dwNewLong = (dwLong And Not FLAGS_COMBI)
End If

Call SetWindowLong(hwnd, nIndex, dwNewLong)
Call SetWindowPos(hwnd, 0&, 0&, 0&, 0&, 0&, wFlags)
End Function
' ********** Code End *************

--
Terry Kreft
MVP Microsoft Access

Tony wrote:
I am continuing to develop an Access 2007 application which was
originally converted from Access 2003. *In Access 2003 I was able to
disable the Access Close button in the top righthand corner of the
screen. *I have been unable to find any way to disable this button in
Access 2007 and subsequently I have been forced to find ways to detect
and handle the situations after the Access Close button has been
clicked.
I have been largely successful, but have encountered once situation
for which I am rapidly running out of ideas.
I have a form which contains a command button. *The command button
opens a report in preview mode. *If I click on the Access Close button
while the report is displayed and the command button's OnClick event
is still running, then control is passed to the report's OnUnload
event and I am able to handle the situation. *This is only true when
the application is running as an .accdb database.
However, if I rename the database to .accdr and repeat the test, as
soon as I click on the Access Close button the application displays
the message "Execution of this application has stopped due to a run-
time error.".
I have since modified the application so that the command button's
OnClick event is closed as soon as the report is displayed. *In this
scenario the .accdr application does not display the error message
when I click on the Access Close button and successfully passes
control to the report's OnUnload event.
Unfortunately, the second scenario was only created as part of my
ongoing research into the problem. *In the real world I want to leave
the command button's OnClick event active so I can perform further
processing once the report has been closed.
I guess I need to understand exactly what happens when the Access
Close button is clicked. *I'm aware that all global variables are lost
- and I can handle that situation. *Any input or ideas would be most
welcome - particularly a way to disable the Access Close button,
which
would solve all my problems!
Thank you, Tony.

--
Please Rate the posting if helps you

Message posted via AccessMonster.comhttp://www.accessmonster.com/Uwe/Forums.aspx/databases-ms-access/2008...- Hide quoted text -

- Show quoted text -
Terry,

Thank you for your suggestions. Unfortunately neither option appears
to solve the problem.

The MS link relates to Access 2000. I have successfully disabled the
Access Close button in Access 2003, but the same code does not produce
the same result in Access 2007.

Your posted code successfully disables the Minimise button on the
Access container form, but has no apparent effect on the Restore or
Close buttons.

Any further inspiration welcomed!

Regards, Tony.
Oct 8 '08 #4
The code from MS works (A2K version) in runtime A2007. It disabled but not
invisible leaving the Min and Max enabled.

The code from Terry Kreft works if your format is A2K. Maybe it's because the
format is accb?

I don't have full A2007, so can't help much.

Tony wrote:
>Terry,

Thank you for your suggestions. Unfortunately neither option appears
to solve the problem.

The MS link relates to Access 2000. I have successfully disabled the
Access Close button in Access 2003, but the same code does not produce
the same result in Access 2007.

Your posted code successfully disables the Minimise button on the
Access container form, but has no apparent effect on the Restore or
Close buttons.

Any further inspiration welcomed!

Regards, Tony.
--
Please Rate the posting if helps you

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200810/1

Oct 9 '08 #5
On Oct 8, 12:47*pm, Tony <tony.abb...@lineone.netwrote:
Your posted code successfully disables the Minimise button on the
Access container form, but has no apparent effect on the Restore or
Close buttons.

Any further inspiration welcomed!

Regards, Tony.
The response to which you replied was not made by Terry. The quoted
code was from Terry.

You might try these functions. They work in Access 2007 for me.

Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd&, ByVal nIndex&)
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&)
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000

Public Function DisableTitleBarControls()
Dim AccessWindowHandle&
Dim WindowStatus&
AccessWindowHandle = Access.hWndAccessApp
WindowStatus = GetWindowLong(AccessWindowHandle, GWL_STYLE)
WindowStatus = WindowStatus And (Not WS_CAPTION)
SetWindowLong AccessWindowHandle, GWL_STYLE, WindowStatus
MsgBox "Title Bar Icons and Control Box Disabled", vbInformation
End Function

Public Function EnableTitleBarControls()
Dim AccessWindowHandle&
Dim WindowStatus&
AccessWindowHandle = Access.hWndAccessApp
WindowStatus = GetWindowLong(AccessWindowHandle, GWL_STYLE)
WindowStatus = WindowStatus Or WS_CAPTION
SetWindowLong AccessWindowHandle, GWL_STYLE, WindowStatus
MsgBox "Title Bar Icons and Control Box Enabled", vbInformation
End Function

I believe that it's wise to craft one's database so that the use of
these and similar functions is unnecessary. Were I driven to it, I'd
probably "grey" the buttons out instead of having them disappear.

I strrongly urge you and anyone else who might want to use these to
study them and read about them carefully. Do a search on the API
functions. Before one uses any code, one should have an understanding
of what it does, and how it does it.
Oct 9 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Peter Frost | last post: by
27 posts views Thread by Wayne | last post: by
1 post views Thread by cpajoe2001 | last post: by
1 post views Thread by rickcross | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.