我有以下代码,它应循环遍历项目中的所有表单,并为每个表单提供一个消息框,其中包含每个表单的设置。我知道循环是正确的,因为我在其他地方使用循环,我只是复制它。为什么消息框是空白的?
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
答案 0 :(得分:2)
如果不打开表单,则无法访问表单属性。您应该只使用Set with objects,而不是字符串。
请参阅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