ms-access - 如何在消息框中显示表单属性?

标签 ms-access vba

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

   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

最佳答案

如果不打开表单,则无法 Access 表单属性。您只能将 Set 与对象一起使用,而不是与字符串一起使用。

参见Access 2010: Which form control fires a macro?

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

关于ms-access - 如何在消息框中显示表单属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10745030/

相关文章:

excel - 根据找到的值将变量分配给另一个单元格

excel - 如何从列分隔的数据集转换为逗号分隔的数据集?

excel - 通过 PowerPoint 自动化 Excel - 本地窗口未公开完整的对象模型(即链接源)

c++ - 使用 Access DB 附加到 SQL 文本字段

ms-access - MS Access 中的 "Operation must use an updateable query"错误

mysql - 是否值得重新制作一个电子商务网站以使用 mySQL 而不是 Access?

excel - 有没有办法循环浏览excel工作表中的所有模块,然后全部删除?

ms-access - 如何在 VBA 中添加/修改 LinkTable 的 'Description' 属性值?

ms-access - 处理大小超过 1 GB 并通过网络 Access 的 Access 数据库

sql - Excel Vba - 在 sql 字符串中使用撇号