473,880 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5900
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_O pen or FormCustomers_L oad. 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*********@li neone.netwrote in message
news:60******** *************** ***********@c36 g2000prc.google groups.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_FRAMECHANGE D = &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_FRAMECHANGE D + SWP_NOMOVE

dwLong = GetWindowLong(h wnd, nIndex)

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

Call SetWindowLong(h wnd, nIndex, dwNewLong)
Call SetWindowPos(hw nd, 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_FRAMECHANGE D + SWP_NOMOVE
Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU

dwLong = GetWindowLong(h wnd, nIndex)

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

Call SetWindowLong(h wnd, nIndex, dwNewLong)
Call SetWindowPos(hw nd, 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.

Unfortunatel y, 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.c om
http://www.accessmonster.com/Uwe/For...ccess/200810/1

Oct 8 '08 #3
On 8 Oct, 08:17, "AccessVand al via AccessMonster.c om" <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_FRAMECHANGE D = &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_FRAMECHANGE D + SWP_NOMOVE

dwLong = GetWindowLong(h wnd, nIndex)

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

Call SetWindowLong(h wnd, nIndex, dwNewLong)
Call SetWindowPos(hw nd, 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_FRAMECHANGE D + SWP_NOMOVE
Const FLAGS_COMBI = WS_MINIMIZEBOX Or WS_MAXIMIZEBOX Or WS_SYSMENU

dwLong = GetWindowLong(h wnd, nIndex)

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

Call SetWindowLong(h wnd, nIndex, dwNewLong)
Call SetWindowPos(hw nd, 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.c omhttp://www.accessmonst er.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.c om
http://www.accessmonster.com/Uwe/For...ccess/200810/1

Oct 9 '08 #5
On Oct 8, 12:47*pm, Tony <tony.abb...@li neone.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 DisableTitleBar Controls()
Dim AccessWindowHan dle&
Dim WindowStatus&
AccessWindowHan dle = Access.hWndAcce ssApp
WindowStatus = GetWindowLong(A ccessWindowHand le, GWL_STYLE)
WindowStatus = WindowStatus And (Not WS_CAPTION)
SetWindowLong AccessWindowHan dle, GWL_STYLE, WindowStatus
MsgBox "Title Bar Icons and Control Box Disabled", vbInformation
End Function

Public Function EnableTitleBarC ontrols()
Dim AccessWindowHan dle&
Dim WindowStatus&
AccessWindowHan dle = Access.hWndAcce ssApp
WindowStatus = GetWindowLong(A ccessWindowHand le, GWL_STYLE)
WindowStatus = WindowStatus Or WS_CAPTION
SetWindowLong AccessWindowHan dle, 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4770
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
7
8882
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
27
45586
by: Wayne | last post by:
I've been clicking around Access 2007 Beta 2 and can't see the custom menu bar designer. Is it in the beta? Maybe I'm blind. The question that comes to mind is: Will custom menu bars be the same height as they were in previous versions or will they be the "ribbon" style that takes up a huge portion of the screen? Also when I use Access 2007 to open an Access 2003 database that has custom menu bars they display as they did in Access...
1
8997
by: cpajoe2001 | last post by:
I am having an issue and after searching around online for a day and half now and finding others with the same problem but yet no solution to my issue I am looking for help. What i have is ServerA which is a webserver running Win2k3 with IIS6, my domain account is a local administrator on this machine. The web app I am running is trying to write a file to ServerB which is also a Win2k3 machine. On the folder of the machine I am writing to...
17
7678
by: Neil | last post by:
A client of mine likes some of the new bells and whistles in Access 2007, and is thinking about converting our A03 format MDB to an A07 format file. However, while some of the users have A07, many do not, and it's not clear when they would get it. His thought was to use the upcoming Access 2007 runtime to allow the users who are still running Office 2003 to be able to run the database. While I use multiple versions of Access on my...
1
4717
by: rickcross | last post by:
I am trying to use the Access 2007 runtime. I have a program that is fully working in 2007 but when I install the runtime version with same Operating system and Access 2003 installed I have multiple errors. One error "Function is not available in table level validation expression." This error occurs three times. when I have a two part delete query or a lookup function that checks for a duplicate entry and a update query that adds a...
2
19510
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2393
by: Tony | last post by:
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...
1
4091
by: BL3WC | last post by:
Hi, I'd created a MDE under Access 2003. It is now under testing stage. Some of the users will use Access 2003 runtime and some will use Access 2007 runtime to run this MDE. I installed the Access 2007 runtime on a test machine and place the MDE in the Desktop for user's initial testing. I did not create a trust area for this MDE in the test machine as well as in my development machine. When I tested the MDE using /runtime switch in my...
0
9925
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10809
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9550
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7104
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5777
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5972
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4595
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.