2

我有以下代码,它应该遍历项目中的所有表单,并给出一个包含每个表单设置的消息框。我知道循环是正确的,因为我在其他地方使用了循环并且我只是复制了它。为什么消息框是空白的?

   For Each frm In CurrentProject.AllForms
         DoCmd.OpenForm frm.Name, acDesign

        mess = "Form: " & frm.Name & vbCrLf & " Allow Addition: " & CStr(frm.AllowAdditions) & vbCrLf & "Allow Deletions: " & CStr(frm.AllowDeletions) & vbCrLf & "     Allow Edit: " & CStr(frm.AllowEdits)
        MsgBox (mess)
        DoCmd.Close acForm, frm.Name, acSaveYes

  Next frm
  Set frm = Nothing

借助 Remou 的提示,我得到了以下工作:

  For Each frm In CurrentProject.AllForms
     DoCmd.OpenForm frm.Name, acDesign
    Set frm = Forms(frm.Name)
    mess = "Form: " & frm.Name & vbCrLf & " Allow Addition: " & CStr(frm.AllowAdditions) & vbCrLf & "Allow Deletions: " & CStr(frm.AllowDeletions) & vbCrLf & "     Allow Edit: " & CStr(frm.AllowEdits)
    MsgBox (mess)
        DoCmd.Close acForm, frm.Name, acSaveNo

  Next frm
  Set frm = Nothing
4

1 回答 1

2

不打开表单就无法访问表单属性。您应该只将 Set 与对象一起使用,而不是与字符串一起使用。

请参阅Access 2010:哪个表单控件触发宏?

For Each f In CurrentProject.AllForms
    DoCmd.OpenForm f.Name, acDesign

    Set frm = Forms(f.Name)
    mess = "Form: " & frm.Name & vbCrLf
    mess = mess & " Allow Addition: " & CStr(frm.AllowAdditions) & vbCrLf
    mess = mess & "Allow Deletions: " & CStr(frm.AllowDeletions) & vbCrLf
    mess = mess & "     Allow Edit: " & CStr(frm.AllowEdits)
    MsgBox mess

    DoCmd.Close acForm, f.Name, acSaveNo
Next
于 2012-05-24T20:54:23.067 回答