然后可以删除docmd.setwarnings行。 如果您要使用docmd.setwarnings,请确保将True语句放入 任何错误处理代码。 *否则奇怪的事情可能会在 之后发生,尤其是在您使用应用程序时。 *例如,您将不再获得 您是否希望保存更改如果您关闭对象,则会显示消息*这可能意味着 将不需要的更改,删除或添加内容保存到您的MDB。 两种方法之间的性能也可能有很大差异。 *一个帖子 声明currentdb.execute花了两秒钟,而docmd.runsql花了八秒钟。 *因为 总是YMMV。 Tony - Tony Toews,Microsoft Access MVP * *请仅在新闻组中回复,以便其他人可以阅读整个消息主题。 * * Microsoft Access Links,Hints ,提示&会计系统:http://www.granite.ab.ca/accsmstr.htm * * Tony的微软Access博客-http://msmvps.com/blogs/access/ The problem with *DoCmd.RunSQ is that it ignores any errors. *Either of the followingwill display any error messages received by the query. *If using DAO, useCurrentdb.Execute strSQL,dbfailonerror.. *For ADO useCurrentProject.Connection.Execute strCommand, lngRecordsAffected, adCmdText * *Youcan then remove the docmd.setwarnings lines.If you''re going to use docmd.setwarnings make very sure you put the True statement inany error handling code as well. * Otherwise weird things may happen later onespecially while you are working on the app. *For example you will no longer get the"Do you wish to save your changes" message if you close an object. *This may meanthat unwanted changes, deletions or additions will be saved to your MDB.Also performance can be significantly different between the two methods. *One postingstated currentdb.execute took two seconds while docmd.runsql took eight seconds. *Asalways YMMV.Tony--Tony Toews, Microsoft Access MVP* *Please respond only in the newsgroups so that others canread the entire thread of messages.* *Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm* *Tony''s Microsoft Access Blog -http://msmvps.com/blogs/access/ 托尼 - 非常感谢!我使用了你的建议(见上面的回复代码) 我也把设置警告和在错误例程中,我在这个应用程序中使用了。我偶尔会有时间 我会说Access并不是在问我有关保存的问题。我很沮丧。 幸运的是,我总是在沙盒中工作。复制并且只在移动代码时 我已经完成了测试。但现在我想*我知道为什么。谢谢! Sara Tony -Many MANY Thanks! I used your suggestion (see code in reply above)and I also put the "Set Warnings" in the error routine everywhere Iused it in this application. I would occasionally have a time whereI''d say "Access isn''t asking me about saving" and I was frustrated.Luckily, I always work in a "sandbox" copy and only move code in whenI''m done testing. But now I *think* I know why. THANKS!! Sara 我以为我发布了这个谢谢你,但我没有看到它所以我再次发布了 。放手吧太重要了! Rich - 谢谢!我花了一些时间来获得变量和SQL,但是我确实这样做了!做到了!我也学到了很多,谢谢你。看下面的代码 : dtmPODate = [Forms]![frmCancelPO]![txtPODate] strDescription = [Forms]![frmCancelPO ]![txtDescription] dtmDateEntered = [Forms]![frmCancelPO]![txtDateEntered] lngMerchantKey = [Forms]![frmCancelPO]![txtMerchantKey] lngVendorKey = [Forms]![frmCancelPO]![txtVendorKey] strPOApproved = [Forms]![frmCancelPO]![txtPOApproved] dtmSuggShipDate = [形式]![frmCancelPO]![txtShipDate] curCostOfGoods = [Forms]![frmCancelPO]![txtCostofGoods] curFreight = [Forms]![frmCancelPO]![ txtFreight] curTotalRetail = [Forms]![frmCancelPO]![txtTotalRetail] dtmPODateToStores = [Forms]![frmCancelPO]![txtPODatetoStores] lngDeptNum = [Forms]![frmCancelPO]![txtDeptNum] strSQL =" INSERT INTO tblPOCancels(PONum,PODate,DateEntered, MerchantKey ,_ &VendorKey,POApproved,SuggShipDate,Description , CostofGoods, _ & " Freight,TotalRetail,PODatetoStores,DeptNum,Reason)" _ & "选择 &安培; lngPONum& ",#" &安培; dtmPODate& #,# & dtmDateEntered _ & #,''" &安培; lngMerchantKey& '',''" &安培; lngVendorKey& '',''" & strPOApproved _ & '',#" &安培; dtmSuggShipDate& #,''" &安培; strDescription& '', & curCostOfGoods _ & , &安培; curFreight& , &安培; curTotalRetail& ",#" &b; b $ b&b #, &安培; lngDeptNum& ",''" &安培; strReason& "''" CurrentDb.Execute strSQL,dbFailOnError 我在CurrentDB.Execute上使用了Tony的建议。现在,如果我能够,只需要记住这一切! 非常感谢 - sara I thought I posted this thank you, but I don''t see it so I''m postingagain. Too important to let it go! Rich -THANK YOU!! It took me a bit to get the variables and SQL right, but Idid it! Learned a lot, too and I thank you for that. See the codebelow:dtmPODate = [Forms]![frmCancelPO]![txtPODate]strDescription = [Forms]![frmCancelPO]![txtDescription]dtmDateEntered = [Forms]![frmCancelPO]![txtDateEntered]lngMerchantKey = [Forms]![frmCancelPO]![txtMerchantKey]lngVendorKey = [Forms]![frmCancelPO]![txtVendorKey]strPOApproved = [Forms]![frmCancelPO]![txtPOApproved]dtmSuggShipDate = [Forms]![frmCancelPO]![txtShipDate]curCostOfGoods = [Forms]![frmCancelPO]![txtCostofGoods]curFreight = [Forms]![frmCancelPO]![txtFreight]curTotalRetail = [Forms]![frmCancelPO]![txtTotalRetail]dtmPODateToStores = [Forms]![frmCancelPO]![txtPODatetoStores]lngDeptNum = [Forms]![frmCancelPO]![txtDeptNum] strSQL = "INSERT INTO tblPOCancels (PONum, PODate, DateEntered,MerchantKey, " _& " VendorKey, POApproved, SuggShipDate, Description,CostofGoods, " _& " Freight, TotalRetail, PODatetoStores, DeptNum, Reason) " _& " Select " & lngPONum & ", #" & dtmPODate & "#, #" &dtmDateEntered _& "#, ''" & lngMerchantKey & "'', ''" & lngVendorKey & "'', ''" &strPOApproved _& "'', #" & dtmSuggShipDate & "#, ''" & strDescription & "'', " &curCostOfGoods _& ", " & curFreight & ", " & curTotalRetail & ", #" &dtmPODateToStores _& "#, " & lngDeptNum & ", ''" & strReason & "''" CurrentDb.Execute strSQL, dbFailOnError I used Tony''s suggestion on CurrentDB.Execute. Now if I can justremember all this! Many thanks -sara 这篇关于Re:附加查询的参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 00:19