Access 2000 - 删除多个表单?

发布于 2024-08-17 03:46:28 字数 52 浏览 4 评论 0原文

无论如何要删除 Access 2000 中的多个表单、查询等吗? (在设计器中就是这样)。

Anyway to Erase multiple forms, queries, etc in Access 2000? (In the designer that is).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌上青苔 2024-08-24 03:46:28

这对我来说效果更好。尝试删除循环本身中的元素一直遇到麻烦。我只是将对象名称放入数组中,然后将其删除。

Public Sub DeleteAllFormsAndReports()

Dim accobj As AccessObject
Dim X As Integer
Dim iObjCount As Integer
Dim sObjectNames() As String

If MsgBox("Are you sure you want to delete all of the forms and reports?", vbCritical + vbYesNo) = vbYes Then
    ReDim sObjectNames(0)
    For Each accobj In CurrentProject.AllForms
        ReDim Preserve sObjectNames(UBound(sObjectNames) + 1)
        sObjectNames(UBound(sObjectNames)) = accobj.Name
    Next accobj

    For X = 1 To UBound(sObjectNames)
        DoCmd.DeleteObject acForm, sObjectNames(X)
    Next X

    ReDim sObjectNames(0)
    For Each accobj In CurrentProject.AllReports
        ReDim Preserve sObjectNames(UBound(sObjectNames) + 1)
        sObjectNames(UBound(sObjectNames)) = accobj.Name
    Next accobj

    For X = 1 To UBound(sObjectNames)
        DoCmd.DeleteObject acReport, sObjectNames(X)
    Next X

End If

结束子

This worked better for me. Trying to remove the elements in the loop itself kept having trouble. I just slapped the object names into an array, then deleted them afterward.

Public Sub DeleteAllFormsAndReports()

Dim accobj As AccessObject
Dim X As Integer
Dim iObjCount As Integer
Dim sObjectNames() As String

If MsgBox("Are you sure you want to delete all of the forms and reports?", vbCritical + vbYesNo) = vbYes Then
    ReDim sObjectNames(0)
    For Each accobj In CurrentProject.AllForms
        ReDim Preserve sObjectNames(UBound(sObjectNames) + 1)
        sObjectNames(UBound(sObjectNames)) = accobj.Name
    Next accobj

    For X = 1 To UBound(sObjectNames)
        DoCmd.DeleteObject acForm, sObjectNames(X)
    Next X

    ReDim sObjectNames(0)
    For Each accobj In CurrentProject.AllReports
        ReDim Preserve sObjectNames(UBound(sObjectNames) + 1)
        sObjectNames(UBound(sObjectNames)) = accobj.Name
    Next accobj

    For X = 1 To UBound(sObjectNames)
        DoCmd.DeleteObject acReport, sObjectNames(X)
    Next X

End If

End Sub

你与昨日 2024-08-24 03:46:28

当用户执行某些操作时,我会即时创建大量查询。因此,我将创建查询,然后在关闭表单后删除该查询。我在“关闭”事件下执行此操作。无论是否创建查询,它都会运行。因此,为了防止出现错误,我告诉它继续下一步。

Private Sub Form_Close()
    On Error Resume Next
    DoCmd.Close acReport, "EmployeeDetails"
    DoCmd.DeleteObject acQuery, "MyEmployeeDetails"
End Sub

I create a lot of queries on the fly when a user performs certain actions. So, I'll create the query, then delete the query once they close the form. I do this under the On Close event. It runs regardless of whether the query was created or not. So, to prevent an error, I tell it to Resume Next.

Private Sub Form_Close()
    On Error Resume Next
    DoCmd.Close acReport, "EmployeeDetails"
    DoCmd.DeleteObject acQuery, "MyEmployeeDetails"
End Sub
吲‖鸣 2024-08-24 03:46:28

您可以使用 VBA 删除对象。从集合中删除时一定要向后退一步,例如,此代码将删除相当多的对象:

Dim db As Database
Dim idx As Long
Dim strName As String

Set db = CurrentDb

    ''Forms
    For idx = CurrentProject.AllForms.Count - 1 To 0 Step -1
        strName = CurrentProject.AllForms(idx).Name
        DoCmd.DeleteObject acForm, strName
    Next idx

    ''Reports
    For idx = CurrentProject.AllReports.Count - 1 To 0 Step -1
        strName = CurrentProject.AllReports(idx).Name
        DoCmd.DeleteObject acReport, strName
    Next idx

    ''Modules
    For idx = CurrentProject.AllModules.Count - 1 To 0 Step -1
        strName = CurrentProject.AllModules(idx).Name
        If strName <> "Module9" Then
            DoCmd.DeleteObject acModule, strName
        End If
    Next idx

    ''Queries
    For idx = db.QueryDefs.Count - 1 To 0 Step -1
        strName = db.QueryDefs(idx).Name
        If Left(strName, 4) <> "~sq_" Then
            db.QueryDefs.Delete strName
        Else
            Debug.Print strName
        End If
    Next idx

    ''Relationships
    For idx = db.Relations.Count - 1 To 0 Step -1
        strName = db.Relations(idx).Name

        If Left(strName, 4) <> "msys" Then
            db.Relations.Delete strName
        Else
            Debug.Print strName
        End If
    Next idx

    ''Tables
    For idx = db.TableDefs.Count - 1 To 0 Step -1
        strName = db.TableDefs(idx).Name
        If Left(strName, 4) <> "msys" Then
            db.TableDefs.Delete strName
        Else
            Debug.Print strName
        End If
    Next idx

You can delete objects with VBA. Be sure to step backwards when deleting from a collection, for example, this code will delete quite a few objects:

Dim db As Database
Dim idx As Long
Dim strName As String

Set db = CurrentDb

    ''Forms
    For idx = CurrentProject.AllForms.Count - 1 To 0 Step -1
        strName = CurrentProject.AllForms(idx).Name
        DoCmd.DeleteObject acForm, strName
    Next idx

    ''Reports
    For idx = CurrentProject.AllReports.Count - 1 To 0 Step -1
        strName = CurrentProject.AllReports(idx).Name
        DoCmd.DeleteObject acReport, strName
    Next idx

    ''Modules
    For idx = CurrentProject.AllModules.Count - 1 To 0 Step -1
        strName = CurrentProject.AllModules(idx).Name
        If strName <> "Module9" Then
            DoCmd.DeleteObject acModule, strName
        End If
    Next idx

    ''Queries
    For idx = db.QueryDefs.Count - 1 To 0 Step -1
        strName = db.QueryDefs(idx).Name
        If Left(strName, 4) <> "~sq_" Then
            db.QueryDefs.Delete strName
        Else
            Debug.Print strName
        End If
    Next idx

    ''Relationships
    For idx = db.Relations.Count - 1 To 0 Step -1
        strName = db.Relations(idx).Name

        If Left(strName, 4) <> "msys" Then
            db.Relations.Delete strName
        Else
            Debug.Print strName
        End If
    Next idx

    ''Tables
    For idx = db.TableDefs.Count - 1 To 0 Step -1
        strName = db.TableDefs(idx).Name
        If Left(strName, 4) <> "msys" Then
            db.TableDefs.Delete strName
        Else
            Debug.Print strName
        End If
    Next idx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文