VBA:表单中的RecordSource列表

时间:2011-10-12 17:30:01

标签: vba ms-access-2007

我想在我的ADP表单中扫描到所有RecordSource。我的一个表单可能会调用错误的视图。它通常设置在RecordSource属性中。问题是我的ADP中有大约300多种表格。所以我想在每种形式中打印所有RecordSource,以便能够找到并纠正问题。这是我到目前为止所做的。

Private Sub Command1_Click()

Dim sForm As String

Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject

Dim cCount As Long
cCount = 0

For Each obj In dbs.AllForms

        ' Print name of obj.
        sForm = "Form_" & obj.name

            Debug.Print cCount  & "  " & Forms(sForm)!RecordSource

        cCount = cCount + 1

Next obj

End Sub

错误是Access无法找到Form。运行时错误'2450'。

1 个答案:

答案 0 :(得分:0)

也许:

For Each obj In dbs.AllForms
    DoCmd.OpenForm obj.Name, acDesign
    Set frm = Forms(obj.Name)
    Debug.Print cCount & "  " & frm.RecordSource

    cCount = cCount + 1
    DoCmd.Close acForm, obj.Name, acSaveNo
Next obj