一张(可能未绑定)Access 2003 表单来创建多个记录
我被招募来制作一份用于追踪标本的表格。每个样本都与一个对象相关联;每个样本在 9 x 9 存储盒中还有一个特定的插槽。为了便于数据输入,我认为最好是 Access 表单镜像框本身(以及将用于将数据输入 Access 的纸质表单):九列乘九行,每个元素基本上由文本组成标本 ID 框。这基本上就是我希望的样子:
因此,数据输入人员基本上会输入框编号和样本 ID,然后单击“创建记录”将所有这些记录弹出(您可以看到这里发生的其他一些事情,但现在这并不重要)。然而,我不太确定编写此代码的最佳方法。现在,我能想到的最好的过程是:1)运行插入查询来创建框(如果不存在),2)运行插入查询来创建主题(人)(如果不存在) ,以及3)对每个样本运行插入查询,在其行和列中进行硬编码(例如box_col = 'A',box_row = '1')。
注意:主题 ID 和样本 ID 都会从 ID 字段中解析出来 - 这很愚蠢,不是我的想法,但这就是它的设置方式。不过我能应付。
这当然是一个拼凑,但我不知道还能做什么,而且我在谷歌上搜索到的大部分内容都与从单一表单创建多记录无关。有更好的方法吗?我是否应该放弃这个想法并采用更传统的绑定子表单方法?
I've been recruited to work on a form for tracking specimens. Each specimen is associated with a subject; each specimen also has a particular slot in a 9 x 9 storage box. For ease of data entry, I think it would be best if the Access form mirrored the box itself (and the paper forms that will be used to enter data into Access): nine columns by nine rows, with each element consisting basically of a text box for the specimen ID. This is basically how I'd like it to look:
So the data entry person would essentially type in the box number and specimen IDs, then click "Create Records" to pop all of those records into existence (you can see some other stuff going on here, but that's not really important right now). I'm not really sure about the best way to code this, however. Right now, the best process I can think of is to: 1) run an insert query to create the box if it doesn't exist, 2) run an insert query to create the subject (person), if it doesn't exist, and 3) run an insert query for each specimen, hard-coding in its row and column (e.g. box_col = 'A', box_row = '1').
Note: the subject ID and specimen ID would both be parsed out of the ID field - it's goofy, not my idea, but that's how it's set up. I can handle that, though.
This is a certainly a kludge, but I'm not sure what else to do and most of what I've googled up hasn't been pertinent to multiple-record creation from a single form. Is there a better way to do this? Should I simply abandon the idea and go with a more traditional bound subform approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
弗里格。我刚刚打字浪费了十分钟。这就是为什么我不喜欢基于网络的表单。公平地说,这是 StackOverflow 上第一次发生这种情况。
您是否确实需要稍后以与输入相同的格式查看数据?如果他们只能查看常规子表单,那么至少完成了一半的工作,因为您不再需要更新此表单。
另请注意,如果我没记错的话,每个表单的生命周期最多有 768 个控件。 9 x 9 x 2 是 162 所以你就可以了。但是,如果您决定删除并重新创建大量控件,您可能会遇到麻烦。如果您确实达到了该限制,我认为以单独的名称保存表单应该重置计数器。
请注意,您可以使用以下构造来引用控件并使生活更轻松。
例如,在类型控件的更新后,您可以使用
FRIG. I just lost ten minutes of typing. This is why I don't care for web based forms. Although to be fair this is the first time this has happened on StackOverflow.
Do you really need to view the data later in the same format as it's entered. If they can just view regular subforms that's at least half the work as you no longer need to do updates of this form.
Also note that there is a lifetime amaximum of 768, if I recall correctly, controls per form. 9 x 9 x 2 is 162 so you'll be ok there. However if you decide to delete and recreate lots of cotrols you could be in trouble. If you do hit that limit I think saving the form under a separate name should reset the counter.
Note you can use the following construct to refer to controls and make life easier.
For example in the After Update of the type control you could use
这可以用作某种仅用于网格的本机访问控制。
如果有人发布一个示例,说明如何创建自定义未绑定子表单,其中包含每个未绑定记录的行以及循环代码并将其保存到表中,那就太好了。
不会有那么多的控件,也不会受到表单上字段数量的任何限制。
This could be used as some kind of native access controls only grid.
If someone would post an example of how to create custom unbound subform with row for each unbound record and a code to loop and save it to the tables would be just great.
There wouldn't be as much controls and it wouldn't have any limits by the numbers of fields on form.
这一切都可以在子表单中完成 - 但是,我假设为了简单起见(更少的点击、更轻松的用户体验和直觉),您已经设计了它,以便最终用户看到他/她需要输入的所有内容。这样做并没有什么错。输入完所有数据后,只需在表单上单击一个按钮即可一次执行多个插入操作。
从 1 开始,每次发出新的 INSERT 语句时都包含 9 次迭代。
一旦语句完成,我个人会在每一行旁边放一个小复选标记,这样如果插入成功,它会检查它是否为真,否则为假。您可以巧妙地使用绿色图像/红色图像。完成该过程后,所有字段都应清除,以允许额外输入。
我不认为你所拥有的有什么问题。
This could be all done in a sub form - however, I assume for simplicity (less clicks, easier user experience, and intuition) you've designed it so that the end user sees everything he /she need to enter. There is nothing wrong with doing it this way. Once the data is all entered just have a button on the form that does the multiple inserts at once.
Start at 1 and include 9 iterations each time issuing a new
INSERT
statement.Once the statement has been completed I would personally put a little check mark next to each row so that if an insert succeded it would check it true, else false. You could be nifty and use a green image / red image. After it has completed the process all fields should be cleared allowing additional entry.
I don't see an issue with what you have.