Access 2010 VBA:acHidden中的OpenForm,然后保存不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17175060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:44:08  来源:igfitidea点击:

Access 2010 VBA : OpenForm in acHidden, then Save does not work

vbaaccess-vbams-access-2010

提问by WJR

I'm trying to open form, change some properties, save, then close the form; all hidden from user.

我正在尝试打开表单,更改一些属性,保存,然后关闭表单;所有对用户隐藏。

For some reason, when I open form with acHidden mode, it throws me Error 29068 cannot complete this operation. You must stop the code and try again.

出于某种原因,当我以 acHidden 模式打开表单时,它抛出错误 29068 无法完成此操作。您必须停止代码并重试。

Here is the code :

这是代码:

    DoCmd.OpenForm "frmProsContractorList", acDesign, , , , acHidden
    DoCmd.Save acForm, "frmProsContractorList"
    DoCmd.Close acForm, "frmProsContractorList"    

If I use acWindowNormalinstead of acHidden, no errors.
If I take out Savemethod, no errors.
It seems like OpenForm with acHidden and Save method does not work.

如果我使用acWindowNormal而不是 acHidden,没有错误。
如果我取出Save方法,则没有错误。
似乎带有 acHidden 和 Save 方法的 OpenForm 不起作用。

Can someone verify if above code works, and how to resolve?

有人可以验证上述代码是否有效,以及如何解决?


WORK-AROUND : below works


解决方法:下面的作品

    DoCmd.OpenForm "frmProsContractorList", acDesign, , , , acHidden
    DoCmd.Close acForm, "frmProsContractorList", acSaveYes    

http://msdn.microsoft.com/en-us/library/ff192860(v=office.14).aspx

http://msdn.microsoft.com/en-us/library/ff192860(v=office.14).aspx

回答by Johnny Bones

You can not edit a form's properties and then save the form. You can, however, edit some of a form's properties without opening the form. If you explain in full detail what you're trying to do, I can edit this answer to tell you how it's achieved. Until then, the answer is, "It can't be done the way you're doing it."

您不能编辑表单的属性然后保存表单。但是,您可以在不打开表单的情况下编辑表单的某些属性。如果您详细解释了您要做什么,我可以编辑此答案以告诉您它是如何实现的。在那之前,答案是,“不能按照你的方式去做。”

EDIT: You can simply set the field's Enabled property to True or False on the form's Load event.

编辑:您可以简单地在表单的 Load 事件上将字段的 Enabled 属性设置为 True 或 False 。

i.e.

IE

MyField.Enabled = False