473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Qutting Access when a dialog box is open

I automatically shut down every PC that is logged into my Access
2000 database at a time that is set on a configuration screen (Around
02:00 AM) . I do this by checking Now() against the ShutDown time about
once per minute in the main menu. This works fine unless an error
dialog box comes up and no one closed it.

The Command DoCmd.Quit will not work in this situation although
other code in the function will run (i.e. MsgBox, Table Inserts, et
cetera)

I can detect that the error dialog is open using a function
suggested by Dev Anish using apiGetWindowLong but I don't know how to
close the offending dialog box or quit Access at that point.

Thanks,
Hank Reed

Nov 13 '05 #1
5 1847
If you can detect the fialog then I'm guesing you have it's hWnd, in that
case just post a WM_CLOSE message to it.

e.g. This looks for the standard message box and closes it if it finds it.

Private Const WM_CLOSE = &H10

Private Declare Function PostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Private Sub Form_Timer()
Dim hWnd As Long
Dim lpClassName As String
Dim lpWindowName As String

lpClassName = "#32770"

hWnd = FindWindow(lpClassName, lpWindowName)
Call PostMessage( _
hWnd, _
WM_CLOSE, _
0, _
ByVal 0&)
End Sub


--
Terry Kreft

"Hank" <ha********@aol.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I automatically shut down every PC that is logged into my Access
2000 database at a time that is set on a configuration screen (Around
02:00 AM) . I do this by checking Now() against the ShutDown time about
once per minute in the main menu. This works fine unless an error
dialog box comes up and no one closed it.

The Command DoCmd.Quit will not work in this situation although
other code in the function will run (i.e. MsgBox, Table Inserts, et
cetera)

I can detect that the error dialog is open using a function
suggested by Dev Anish using apiGetWindowLong but I don't know how to
close the offending dialog box or quit Access at that point.

Thanks,
Hank Reed

Nov 13 '05 #2
I wonder if the same happens if a form is left opened in 'dialog'
mode... it would explain why my automatic shutdown sometimes fails

Hank wrote:
I automatically shut down every PC that is logged into my Access
2000 database at a time that is set on a configuration screen (Around
02:00 AM) . I do this by checking Now() against the ShutDown time about
once per minute in the main menu. This works fine unless an error
dialog box comes up and no one closed it.

The Command DoCmd.Quit will not work in this situation although
other code in the function will run (i.e. MsgBox, Table Inserts, et
cetera)

I can detect that the error dialog is open using a function
suggested by Dev Anish using apiGetWindowLong but I don't know how to
close the offending dialog box or quit Access at that point.

Thanks,
Hank Reed


Nov 13 '05 #3
I put Terry's two functions in the Declaration section of my Main Menu
and made the call below from the Timer Event.

When I execute this line:
hWnd = FindWindow(lpClassName, lpWindowName)

I get an error message:
"To set this property open the report or form in design view"

I notice we are not initializing lpWindowName - Is that correct
Hank Reed

Nov 13 '05 #4
If your doing this in a form then change the declaration of the variable
hWnd.

e.g.
Dim lnghWnd As Long
Dim lpClassName As String
Dim lpWindowName As String

lpClassName = "#32770"

lnghWnd = FindWindow(lpClassName, lpWindowName)
Call PostMessage( _
lnghWnd, _
WM_CLOSE, _
0, _
ByVal 0&)
You are getting this erro because hWnd is a property of the form, changing
the name of the variable will sort that out.

Yes lpWindowName should be an empty string for this purpose. we could have
done this

Dim lnghWnd As Long
Dim lpClassName As String

lpClassName = "#32770"

lnghWnd = FindWindow(lpClassName, "")

.... but as I was just knocking out the code I didn't bother too musch with
cleaning up.

I would have thought though as you already have a routing t oidentify the
dialog you would have it's hWnd (by this I mean the handle to the window),
you kust need to substitute that value for the lnghWnd variable above.
--
Terry Kreft

"Hank" <ha********@aol.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I put Terry's two functions in the Declaration section of my Main Menu
and made the call below from the Timer Event.

When I execute this line:
hWnd = FindWindow(lpClassName, lpWindowName)

I get an error message:
"To set this property open the report or form in design view"

I notice we are not initializing lpWindowName - Is that correct
Hank Reed

Nov 13 '05 #5
Terry,
Sorry about my confusion. Your method now works quite
well.
Thanks for staying with me on this problem.
Hank Reed

Terry Kreft wrote:
If your doing this in a form then change the declaration of the variable
hWnd.

e.g.
Dim lnghWnd As Long
Dim lpClassName As String
Dim lpWindowName As String

lpClassName = "#32770"

lnghWnd = FindWindow(lpClassName, lpWindowName)
Call PostMessage( _
lnghWnd, _
WM_CLOSE, _
0, _
ByVal 0&)
You are getting this erro because hWnd is a property of the form, changing
the name of the variable will sort that out.

Yes lpWindowName should be an empty string for this purpose. we could have
done this

Dim lnghWnd As Long
Dim lpClassName As String

lpClassName = "#32770"

lnghWnd = FindWindow(lpClassName, "")

... but as I was just knocking out the code I didn't bother too musch with
cleaning up.

I would have thought though as you already have a routing t oidentify the
dialog you would have it's hWnd (by this I mean the handle to the window),
you kust need to substitute that value for the lnghWnd variable above.
--
Terry Kreft

"Hank" <ha********@aol.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I put Terry's two functions in the Declaration section of my Main Menu
and made the call below from the Timer Event.

When I execute this line:
hWnd = FindWindow(lpClassName, lpWindowName)

I get an error message:
"To set this property open the report or form in design view"

I notice we are not initializing lpWindowName - Is that correct
Hank Reed


Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
23
by: JustMe | last post by:
I don't know if this has anything to do with AccessXP running on Terminal Services with Access97/2000 also installed, but here is one example of a query that does not work any longer: SELECT...
6
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...
7
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...
3
by: Jorge Cecílio | last post by:
Hi! I would like to export some MS-Access reports output to pdf. However, the only possibility offered by Access (afaik) for me to export formatted output is snp (snapshot) (I use MS-Office...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
3
by: Jeremy Wallace | last post by:
Anyone know how we can open the add table dialog in an Access 2000 ADP that's using a SQL Server back end? We've got the toolbars and menus locked down and are using custom ones. When they open...
4
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
8
by: Arno R | last post by:
Hi all. When I need to search for pictures, I always have too choose thumbnail-view manually. Is it possible to open the common dialog in thumbnail-view programmatically? Example ?? At the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.