使用相同的字段和表组合多个查询
我有一份订单信息表格。从表单上的组合框中选择订单号后,它将填充订单日期、产品信息、客户 ID 等字段(所有这些信息的来源是 OrderInfo 表)。我有一个单独的 CustomerInfo 表,其中包含客户 ID、姓名、地址...表单上有四个客户 ID 字段。我想根据客户 ID 字段自动显示姓名、地址...。
我对第一个客户进行了查询,以查找表单上的客户 ID 值并找到姓名和名称。地址。但我不想为四个客户 ID 字段编写四个查询。有没有什么方法可以将所有四个合而为一,或者有没有更好的方法来完成此过程?
I have a Form for order information. It will populate the fields order date, product info, Customer ID... after selecting the Order number from a combo box on the form(Source for all this information is OrderInfo table). I have a separate table for CustomerInfo which has Customer ID, name, address... There are four Customer ID fields on the form. I want to automatically display the name, address... based on Customer ID field.
I did a query for the first customer to look for the customer ID value on the form and find the name & address. But I do not want to write four queries for the four customer ID fields. Is there any way to combine all four into one or is there a way better to do this process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 June7 评论的那样,八行 DLookup 代码可能是最快的解决方案。
我个人不喜欢使用 DLookup,并且我确信它们是比我建议的更优雅的解决方案,但下面是我尝试过的(并且我假设未绑定文本框)。
在表单上创建一个私有子例程:
然后在填充 CustomerID 后(如您提供的图像所示),调用此子例程,并为其提供 CustomerID、客户姓名的文本框名称以及客户的地址。运行一个循环可能会更好,但由于您只有四个记录要填充,这可能是最直接的:
不幸的是,我不确定您如何设置数据库,因此这可能不一定有效。让我知道。
As June7 commented, eight lines of DLookup code might be the quickest solution.
I don't personally like to use DLookup, and I'm sure their is a more elegant solution than what I'm suggesting, but below is what I tried (and I assumed unbound textboxes).
Create a private subroutine on the form:
Then after whatever populates the CustomerID (as shown in the image you provided), call this subroutine, and give it the CustomerID, the name of textbox for the customer's name, and the name of the textbox for the customer's address. Could be better running a loop, but since you only have four records to fill, this might be the most straight forward:
Unfortunately, I'm not sure how you have your database setup, so this may not necessarily work. Let me know.