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