将记录/传输PK值从Listbox添加到子表单(数据表)。 [英] Add record/ transfer PK value from Listbox to subform(datasheet).

查看:64
本文介绍了将记录/传输PK值从Listbox添加到子表单(数据表)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表框中选择包含主键的产品。我想在选择产品后打开另一个表单,新打开的表单的子表单显示所选的产品详细信息。我尝试了各种各样的解决方案,但没有任何方法可以正常使用。这就是我目前正在使用的 - 一段简单的添加记录代码。请注意,如果我手动插入产品ID,则其余数据如下:

I select a product on a listbox that includes the Primary Key. I want to open another form, once a product is selected, with the subform of the newly opened form displaying the selected product details. I have tried all manner of ''solutions'' but nothing has worked properly. This is what I am currently using - a simple piece of add record code. Note that if I manually insert the product ID then the rest of the data follows...

展开 | 选择 | Wrap | 行号

推荐答案

请原谅有缺陷的标签......
Please excuse faulty tags....


你好Stonward :)


我不确定我是否理解思考过程这里完全给出RecordsetClone是只读的。我得到了你正在做的事情的原则,并且有不同的方法来做到这一点。这是一个设计问题我接受是否使用早期绑定/后期绑定或绑定/未绑定表单并使用VBA addnew或SQL插入语句插入记录。


无论如何要刺穿你的问题....看了你发布的代码我总结你只想根据列表框的内容添加一个基础表的记录(当然有一个错误处理和验证的程度可以进入这里,但我会让你处理那个


我已经找到了一个简单的数据库供你查看,它往往遵循你的命名惯例( 虽然我确定不是在每个领域)。包含VBA AddNew方法(虽然我更喜欢自己的一行SQL插入错误处理taboot )注意定义的SQL记录集我调用空白一行只是为了添加记录而调用整个表记录集。


我有目的地没有过于优雅,高效或干净,这些代码背后的代码有利于您在考虑时获得 IF 验证逻辑序列你打算扔的数据。 (注意现有记录的计数以便不重复等


无论如何希望它可以帮助你一些:)





Hi Stonward :)

I am not sure I understand the thought process here fully given the RecordsetClone is read only. I get the principle of what you are doing and there are different ways to do it. It is a matter of design I accept whether one uses early binding/late binding or bound/unbound forms and inserting records using VBA addnew or SQL insert statements.

Anyway to have a stab at your question.... having looked at your posted code I summize you are wanting to merely add a record to an underlying table based on the contents of a listbox (of course there is a magnitude of error handling and validation one could get into here but I will let you deal with that)

I have knocked up a simple databse for you to have a look at that tends to follow your naming convention (although I am sure not in every area). There is the VBA AddNew method included (although I prefer myself one line SQL inserts with error handling taboot) Notice the defined SQL recordset I am calling a blank one row namely not calling up the entire table recordset just to add a record.

I have purposefully not been too graceful,efficient or clean with this code behind the forms in favour of you getting the IF validation logic sequences in there when considering the data you intend to throw about. (notice the counting of existing records so as not to duplicate etc)

Anyway hope it helps you some :)
Attached Files
stoneward.zip (35.4 KB, 164 views)


你不是很清楚你是什么我想这么做。你能用现实世界的术语来解释你的情况吗?我注意到你似乎试图将一条记录添加到表单的记录集中,这有点奇怪。


对于初学者,数据可以传递给打开的表单在代码中使用 OpenArgs 参数。还可以通过 WhereCondition 参数告知表单专门处理某个项目或一组项目。


我希望您的解决方案位于某处这些线条,但没有理解你试图做的清楚,它很难知道哪个。


PS。不用担心标签。你付出了努力,这是重要的事情。
It''s not very clear what you''re trying to do. Can you explain your situation in real-world terms? I noticed you appear to be trying to add a record to a form''s recordset, which is a little weird.

For starters, data can be passed to a form that is opened in code by using the OpenArgs parameter. A form can also be told to deal exclusively with a certain item, or set of items, with the WhereCondition parameter.

I expect your solution lies somewhere along these lines, but without understanding what you''re attempting to do clearly enough it''s hard to know which.

PS. No worries about the tags. You made the effort and that''s the important thing.


这篇关于将记录/传输PK值从Listbox添加到子表单(数据表)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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