11

私は現在Application.Quit、MSAccessアプリケーションのシェルを開いたままにするものを使用しています。

ターゲットアプリケーションに対して呼び出し元の関数を処理した後、アプリケーションのすべてのインスタンスが開いたままになります。特定のデータベースインスタンスが閉じている場合でも。

VBAを使用してプログラムでデータベースの「シェル」アプリケーションウィンドウを閉じるにはどうすればよいですか?

変数がどのように作成され、どのように閉じるかの例を次に示します。

Dim appAccess As New Access.Application

' Do stuff here...

appAccess.CloseCurrentDatabase
4

6 に答える 6

9

According to the documentation: Application.Quit does the same thing as DoCmd.Quit. Namely

The Quit method quits Microsoft Access. You can select one of several options for saving a database object before quitting.

You can try calling either of them with the parameter acQuitSaveNone or 2 which "Quits Microsoft Access without saving any objects". Upon further review, use Application.Quit as DoCmd.Quit was added for backward compatibility for Access 95 (See remarks for Quit Method as it applies to the DoCmd object.) Doing either of these should still do an automatic compact on close if you have the permissions, which may be the cause of you shells.

If that doesn't work for you, here is a somewhat extreme suggestion. Save this as a vbscript file and call it once you're truly done with Access. This will terminate all MSAccess processes on your windows pc, without compacting and repairing.

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Process WHERE Name = 'msaccess.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

To call the script replacing [vbspath] with the actual path. If the path has spaces make sure to use double quotes and put it in quotes:

shell "cscript [vbspath]"
于 2012-09-17T22:22:36.157 に答える
6

私はいつもを使用しますDoCmd.Quit acQuitSaveAll
これは、少なくともAccess 2000、2003、および2010で機能します(これが機能することを確認しまし)。

于 2012-09-17T21:51:35.970 に答える
5

Access.Quit私のために働きます。代わりにそれを試してみてくださいApplication.Quit

それでも解決しない場合は、問題が別の場所にある可能性があります。その場合は、このプロジェクトについて詳しく教えてください。

于 2012-09-17T21:07:18.487 に答える
3

DoCmd.Quit acQuitSaveAll、ようやく機能しました。以前に他のすべてのオプションを試しましたが、シェルがまだぶら下がっていました。

于 2014-09-25T21:23:59.920 に答える
0

フォームをデザイン ビューに切り替えます。フォームのBorderStyleプロパティを に設定しNoneます。[表示] メニューの[フォーム ビュー] をクリックします。フォームのタイトル バーが完全に削除されていることに注意してください。

于 2015-06-03T11:55:31.960 に答える