各位大大好,
我想要在 vba 可以寫個關閉所有開啟在 Access 2016 裡面開啟的東西.
我 google 了一下 找到了下面的 coding, 但是執行的時候跳出錯誤訊息 "編輯錯誤, 使用者自訂型態尚未定義" 不知道哪裡需要定義 怎麼定義? 麻煩大大幫一下忙, 謝謝.
或者有其他方法可以關閉所有視窗.
Private Sub Command0_Click()
Dim tbl As TableDef
Dim qr As QueryDef
Dim rpt As Report
Dim frm As Form
For Each tbl In CurrentDb.TableDefs
DoCmd.Close acTable, tbl.Name
Next tbl
For Each qr In CurrentDb.QueryDefs
DoCmd.Close acQuery, qr.Name
Next qr
For Each rpt In Application.Reports
DoCmd.Close acReport, rpt.Name
Next rpt
For Each frm In Application.Forms
If frm.Name <> "LoginFormName" Then DoCmd.Close acForm, frm.Name
Next frm
End Sub
Dim AccD As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
For Each AccD In dbs.AllForms
If AccD.IsLoaded = True Then
DoCmd.Close acForm, AccD.Name, acSaveYes
End If
Next AccD
其他的自己發揮一下
改成 AllQueries and acQuery 停在錯誤 dbs.AllQueries 那行
Dim AccD As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
For Each AccD In dbs.AllQueries
If AccD.IsLoaded = True Then
DoCmd.Close acQuery, AccD.Name, acSaveYes
End If
Next AccD
抱歉,沒注意到,改一下寫法就可以了
Dim AccD As AccessObject, dbs As Object
Set dbs = Application.CurrentData.AllQueries
For Each AccD In dbs
If AccD.IsLoaded = True Then
DoCmd.Close acQuery, AccD.name, acSaveYes
End If
Next AccD