Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to close Access when macro finished.

Status
Not open for further replies.

modglin

Programmer
Apr 10, 2001
105
I have created a macro that goes to an address gets the .txt information and appends it to a table. I need to have this macro run automatically at midnight. I was able to figure out how to run it every 24 hours IF a form was open, however, not sure how to get this to open access, run the macro with /x APPENDSESSIONLOG and close access.
I believe I can get someone to help me create a batch file in DOS:
c:\cd program fils\microsoft office\office
msaccess \\wallis6\backup\telelog /x appendsessionlog

If I run those two lines from a dos prompt it does open access and append the information, however, I am not sure how to close the program.

As I am sure you can tell - I know nothing about Visual Baicis!
 
THANKS!!! I tried every word but quit!
I tried Exit, Close and etc. Thanks again.
 
modglin,
Paste the following code in the General Declarations section of the Module:

Public Const WM_CLOSE = &H10

Declare Function findwindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

THEN
Paste in the following function:

Public Function EndItAll()
Dim hWnd As Long

'Find the window handle for a application called "Microsoft Access"
hWnd = findwindow(vbNullString, "MICROSOFT ACCESS")

'Close that window and all child windows (this kills the process)
Call SendMessage(hWnd, WM_CLOSE, 0&, 0&)

End Function

Then call the function from your macro or whatever, after your appending work is done.

WARNING!!! This is a crowbar solution. It *will* shut down an access database, but it does not care which one, so if you have more than one running, it could pick any one of them and shut it down. I use this because I know I will only have one Access database running at the time I run this code.

I know you said you don't know VB, but this is the only solution I've ever come up with to do what you're wanting to accomplish. There is a function or something that will close the current database, but it leaves Access running. It didn't sound like that was what you wanted to do.

Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top