讨论在代码和表单中编辑数据 [英] Discuss Editing Data in Code AND on Form

查看:59
本文介绍了讨论在代码和表单中编辑数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[Admin(NeoPa)Addition]

这个新线程是从现有的线程创建的(添加另一个搜索/修改到DAO记录集搜索),因为讨论与线程问题无关。 />

ZMBD:

Abhean -

如果我正确地遵循你的代码。 ..我强烈建议AGAINST使用代码和表单来编辑来自双方的开放记录集。记录 - 你要求数据库崩溃!



NeoPa,抱歉,我从上面删除(注释掉)第9行和第10行,所以现在只需打开修改表单。只需使用搜索查看是否已有记录或是否需要添加记录。


Zmbd,请详细说明。在第二次OpenRecordset时,我很紧张。名副其实,但不确定是否有任何其他方式。希望。关闭。在第一个With结束时关闭rst OpenRecordset。


如果你不能告诉我这是一个新的计算我的一个学期的数据库。 :)


在我需要的代码中(首先)检查并添加记录到我的罗氏中的方法。当用户扫描它时,用于QR码的表格。


然后我需要代码来检查另一个表格,使用已经从QR码中删除的另一个变量来检查它是否是已经在MaterialNum中表。如果未找到,我打开一个表单来修改该记录中的所有字段,该表单将信息保存到表中。信息被传递给来自viaTempVars。

展开 | 选择 | Wrap | 行号

解决方案

Abhean ,

请接受我的道歉让你久等了

卡车上的大家庭,破裂的挡风玻璃等......正常生活的东西;-)


在这里偏离主题的风险,我认为值得看看你的代码,以确保你在这里问的问题不会给你带来麻烦 - 我们如果需要可以随时拆分线程:):


(+)

第41,45,48,57行......

使用并不常见在设置对象的method-property之前调用语句。取而代之的是调用语句用于将控制转移到诸如子函数,函数和/或外部代码(如DLL,Powershell或批处理文件)之类的过程。

在VBA-IDE中如果微软改变主意,就不会对你所拥有的结构感到困惑。


(+)

第82行:DO不要关闭你的数据库对象!

在我的早期,我不能告诉你我做了多少次,然后有关于数据库的错误。

>经验法则:

如果 设置它,你清除它

如果 打开它关闭它。


我还会更改第81行和第85行之间的代码,以便您以LIFO顺序释放对象,以减少孤立记录或泄漏的可能性记忆:

展开 | 选择 | Wrap | 行号

呀。关闭主题。


如果有合适答案的帖子需要进一步的技术讨论,这是非常不寻常的。如果需要,那么这是一个不同的主题&不同的主题,您可以期待主持人为您移动它。


显然,理想情况下,自己创建新主题并简化所有内容:-)


这是一个有趣的问题,值得一看。将它隐藏在另一个问题的线程中将确保它主要被忽视。


当然它是:)


我想制作确保OP在将它们拆分为新线程之前有机会查看帖子。感谢您抽出宝贵时间为我做这件事!


[Admin (NeoPa) Addition]
This new thread was created from an existing one (Adding another search/modify to DAO recordset search) as the discussion was not related to the question of the thread.

ZMBD:
Abhean -
If I am following your code correctly... I highly advise AGAINST using both the code and the form to edit an open recordset from "both sides" of the record - you''re begging for the database to implode!

NeoPa, sorry I removed (commented out) lines 9 and 10 from above, so it is now just opening the modification form. Just using the search to see if there is a record already there or if one need to be added.

Zmbd, please elaborate. I was nervous at doing the second "OpenRecordset" veritable but wasn''t sure of any other way. Was hoping that the ".Close" at the end of the first "With" closed down "rst" OpenRecordset.

If you cant tell I am relitive new to this counting my 1 semester of database. :)

Within the code I needed (to start with) a way to check and add a record into my "Roche" table for a QR code when the user scanned it in.

Then I need the code to check another table using a different variable that has already been stripped from the QR code to check if it is already in the "MaterialNum" table. If Not found I open a form to modify all the fields in that record and that form saves the info onto the table. Info is passed to the from via "TempVars".

Expand|Select|Wrap|Line Numbers

解决方案

Abhean,
Please accept my apologies for keeping you waiting
Large family, cracked windshield in the truck, etc... normal life stuff ;-)

At the risk of going way off topic here, I think it''s worth taking a look at your code to make sure that what you''re asking here doesn''t get you in trouble - we can always split the thread if needed :) :

(+)
Line 41, 45, 48, 57, etc....
It''s not common to use the Call statement before the method-property of an instituted object. Instead the Call Statement is used for transferring control to a procedure such as a Sub, Function, and/or external code such as a DLL, Powershell, or Batch file.
While the VBA-IDE doesn''t choke on the construct you have - just something to be aware of if Microsoft changes its mind.

(+)
Line 82 : DO NOT CLOSE YOUR DATABASE OBJECT!
In my early days I cannot tell you how many times I did this and then had errors relating to the database.
>Rule of thumb:
If you set it you clear it
If you open it you close it.

I would also change the code between lines 81 and 85 so that you release objects in LIFO order to reduce the chance of orphaning records or leaking memory:

Expand|Select|Wrap|Line Numbers


Yeah. Off topic.

It''s very unusual for a thread with an appropriate answer to need any further technical discussion. If such is required then it''s a different topic & different thread and you can expect a moderator to move it for you.

Obviously, and ideally, create the new thread yourself and simplify everything :-)

This IS an interesting question and deserves to be seen. Hiding it in a thread for another question would ensure it''s mainly overlooked.


Of Course it was :)

I wanted to make sure that OP had a chance to see the post(s) before splitting them out to a new thread. Thank you for taking the time to do so for me!


这篇关于讨论在代码和表单中编辑数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆