Microsoft Access-具有来自不同表的多个条件的Dlookup [英] Microsoft Access - Dlookup with multiple criteria from different tables

查看:333
本文介绍了Microsoft Access-具有来自不同表的多个条件的Dlookup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有2个表.一个叫做制造",另一个叫做产品".

I have 2 tables in my DB. One called Manufacture and the other Product.

制造"表具有2个字段:

The Manufacture table has 2 fields:

  • 号码
  • 名称

产品"表具有3个字段:

The Product table has 3 fields:

  • 号码
  • 名称
  • 生产编号

我想要的是创建新产品时,它会告诉我该产品是否已经存在.我目前正在使用此代码:

What I want is When I create a new product, it shows me if the product already exists. I'm currently using this code:

DLookup("[Name]", "Product", "[Name] = '" & me.txtName.value & "'")

它工作得很好,但是一旦发生相同名称但制造商不同的产品.因此,我无法创建记录.

It works just fine, but once happened that a product with the same name but different manufacture. I could not create a record because of that.

我只能创建与已创建的产品和制造相同的新记录.

I only could not create a new record if the is the same product and the same manufacture as already created.

如何为不同表中的多个条件创建一个Dlookup?

How do I create one Dlookup for multiple criteria in different tables?

推荐答案

我怀疑您真的不想查看不同的表.您要避免添加与现有产品具有相同名称和制造商的产品,因此要检查Product表中的两个字段:

I suspect that you don't really want to look across different tables. You want to prevent adding a product with the same name and manufacturer as an existing product, so you want to check both fields in the Product table:

DLookup("[Name]", "[Product]", "[Name] = '" & me.txtName & "' And Manufacture_Number = " & me.txtMfrNumber)

制造商的输入控件很可能是组合框,但也可以使用-只需将txtMfrNumber替换为用于获取此编号的控件的名称即可.

It's more likely that your input control for the manufacturer is going to be a combo box, but that works too - just replace txtMfrNumber with the name of the control that you're using to get this number.

请注意,您无需在me.txtName的末尾指定.Value,因为Value是文本框的默认属性.

Note that you don't need to specify the .Value on the end of me.txtName as Value is the default property of your text box.

这篇关于Microsoft Access-具有来自不同表的多个条件的Dlookup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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