没有获得第二个组合框的值“with”声明& Dcount帮助 [英] Not getting value for second combo box "with" statement & Dcount help

查看:46
本文介绍了没有获得第二个组合框的值“with”声明& Dcount帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我来这里很新(使用Access 2000),并欣赏

的帮助和指示。


我给自己2.5小时在线研究和帮助,并尝试获得这个

一个,我没有得到它。


简单的数据库:我希望用户通过Item输入Supply Orders(仅用于

跟踪目的)。用户还可以输入新项目 - 新

是Item,PartNumber和Vendor的组合 - 他们可以拥有

相同的项目和从a购买的partnumber不同来源。


物品和供应商是自我更新的。组合框 - 添加项目如果它不是列表中的



我试图接受用户的输入:Item,供应商和PartNumber以及

使用Dcount来查看该组合是否真的是新的还是已经存在。


我无法让供应商在我的展示中显示码。我有各种各样的msg

盒子和供应商丢失了。我正在使用一些With我在

这个网站上找到的条款从组合框中获取值,因为我之前无法得到那些

值。


这里是代码:

Dim intcount As Integer

Dim tblSupplies As TableDef

Dim PartNumber As String

Dim frm As Form


Dim Vendor As Control

Dim Item as Control


Set Item = Me.cboItem

With Item

''Column(0)包含" PartID" ......这里我们不需要。

我![项目] = .Column(1)

结束

MsgBox项目& "是这里的项目(是)


与供应商

我![供应商] = .Column(1)

结束使用

MsgBox在这里是供应商(否) &安培;供应商


''查看此供应是否已经在tblSupplies

PartNumber = Me.PartNumber


' '在这里调试

MsgBox" item: &安培;项目& " PN &安培; PartNumber& " Ven &安培;供应商

intcount = DCount(" [Item]"," tblSuppplies"," [Item] ="& Item and _

[PartNumber] =&& PartNumber和[Vendor] ="& Vendor)


''用于调试:

MsgBox intcount


如果intcount<> 0然后

Err.Description = _

此供应品号 - 供应商已存档。请检查

您的参赛作品。

GoTo Err_cmdAddItem_Click

Else


DoCmd.GoToRecord, ,acNewRec


结束如果

Hi
I''m pretty new to Access here (using Access 2000), and appreciate the
help and instruction.

I gave myself 2.5 hours to research online and help and try to get this
one, and I am not getting it.

Simple database: I want to have a user enter Supply Orders (just for
tracking purposes) by Item. The user may also enter a new item - "new"
is a combination of Item, PartNumber and Vendor - they could have the
same item and partnumber purchased from a different source.

Item and Vendor are "self-updating" combo boxes - adds the item if it''s
not in the list.

I am trying to take the user''s input: Item, Vendor and PartNumber and
use Dcount to see if that combination is really NEW or already exists.

I can''t get the Vendor to show in my code. I have had all sorts of msg
boxes and vendor is missing. I am using some "With" clauses I found on
this site to get the value from combo boxes as I couldn''t get those
values before.

Here''s the code:
Dim intcount As Integer
Dim tblSupplies As TableDef
Dim PartNumber As String
Dim frm As Form

Dim Vendor As Control
Dim Item As Control

Set Item = Me.cboItem
With Item
'' Column(0) contains "PartID" ... which we don''t need here.
Me![Item] = .Column(1)
End With
MsgBox Item & " is item here (yes)"

With Vendor
Me![Vendor] = .Column(1)
End With
MsgBox "is vendor here (no)" & Vendor

'' Find out if this supply is already on tblSupplies
PartNumber = Me.PartNumber

'' debug here
MsgBox " item: " & Item & " PN " & PartNumber & " Ven " & Vendor
intcount = DCount("[Item]", "tblSuppplies", "[Item] = " & Item And _
[PartNumber] = " & PartNumber And [Vendor] = " & Vendor)

'' For debugging:
MsgBox intcount

If intcount <> 0 Then
Err.Description = _
"This Supply-Part Number - Vendor is already on file. Please check
your entry."
GoTo Err_cmdAddItem_Click
Else

DoCmd.GoToRecord , , acNewRec

End If

推荐答案

> intcount = DCount(" [Item]"," tblSuppplies"," [Item] ="& Item And _
> intcount = DCount("[Item]", "tblSuppplies", "[Item] = " & Item And _
[PartNumber] ="& PartNumber And [Vendor ] ="&供应商)


你在引号外面有单词AND,它应该在它们里面。


intcount = DCount ([Item],tblSuppplies,[Item] ="& Item&" And"& _

" [PartNumber] =" ;& PartNumber&" And [Vendor] ="& Vendor)


您所使用的语法也表明这些值是数字数据

类型,如果它们是文本,则需要进行一些修改。


另一种选择是在表中使用多字段索引并将其设置为

没有重复。这将阻止将这三个字段

相同的记录添加到表中的任何记录。如果你已经有一些

已经存在,那么在你更正当前的

数据之前,你将无法设置索引。


-

Wayne Morgan

MS Access MVP

" sara" < SA ****** @ yahoo.com>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...嗨我在这里访问是非常新的(使用Access 2000),并感谢
帮助和指导。

我给自己2.5小时在线研究并帮助并试图获得这个
一个,我没有得到它。

简单的数据库:我希望用户通过Item输入Supply Orders(仅用于跟踪目的)。用户还可以输入新项目 - new
是Item,PartNumber和Vendor的组合 - 他们可以从不同的来源购买相同的商品和部件号。
<项目和供应商是自我更新的。组合框 - 如果项目不在列表中,则添加项目。

我正在尝试接受用户的输入:项目,供应商和零件编号以及
使用Dcount来查看该组合是真的是新的还是已经存在。

我无法让代码显示在我的代码中。我有各种各样的msg
盒子和供应商丢失。我正在使用一些With我在
这个网站上找到的条款,以便从组合框中获取价值,因为我之前无法获得这些值。

这里是代码:
Dim intcount As Integer
Dim tblSupplies As TableDef
Dim PartNumber As String
Dim frm As Form

昏暗的供应商作为控制
Dim Item As Control

Set Item = Me.cboItem
With Item
''Column(0)包含" PartID" ......这里我们不需要。
我![项目] = .Column(1)
结束
MsgBox项目& "是商品在这里(是)

与供应商
我![供应商] = .Column(1)
结束与
MsgBox"是供应商在这里(否)" &安培;供应商

''找出这个供应是否已经在tblSupplies
PartNumber = Me.PartNumber

''在这里调试
MsgBox" item: &安培;项目& " PN &安培; PartNumber& " Ven &安培;供应商

intcount = DCount(" [Item]"," tblSuppplies"," [Item] ="& Item And _
[PartNumber] =&& ; PartNumber和[Vendor] ="& Vendor)

''用于调试:
MsgBox intcount

如果intcount<> 0然后
Err.Description = _
此供应品号 - 供应商已存档。请检查您的输入。
GoTo Err_cmdAddItem_Click
否则

DoCmd.GoToRecord,acNewRec

结束如果
[PartNumber] = " & PartNumber And [Vendor] = " & Vendor)
You have the word AND outside the quotes, it should be inside them.

intcount = DCount("[Item]", "tblSuppplies", "[Item] = " & Item & " And " & _
"[PartNumber] = " & PartNumber & " And [Vendor] = " & Vendor)

The syntax you have also indicates that these values are a numeric data
type, if they are text a little modification will need to be made.

Another option would be to use a multifield index in the table and set it to
no duplicates. This will prevent any record where all three of these field
are identical from being added to the table. If you have some in there
already, you won''t be able to set the index until you correct the current
data.

--
Wayne Morgan
MS Access MVP
"sara" <sa******@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Hi
I''m pretty new to Access here (using Access 2000), and appreciate the
help and instruction.

I gave myself 2.5 hours to research online and help and try to get this
one, and I am not getting it.

Simple database: I want to have a user enter Supply Orders (just for
tracking purposes) by Item. The user may also enter a new item - "new"
is a combination of Item, PartNumber and Vendor - they could have the
same item and partnumber purchased from a different source.

Item and Vendor are "self-updating" combo boxes - adds the item if it''s
not in the list.

I am trying to take the user''s input: Item, Vendor and PartNumber and
use Dcount to see if that combination is really NEW or already exists.

I can''t get the Vendor to show in my code. I have had all sorts of msg
boxes and vendor is missing. I am using some "With" clauses I found on
this site to get the value from combo boxes as I couldn''t get those
values before.

Here''s the code:
Dim intcount As Integer
Dim tblSupplies As TableDef
Dim PartNumber As String
Dim frm As Form

Dim Vendor As Control
Dim Item As Control

Set Item = Me.cboItem
With Item
'' Column(0) contains "PartID" ... which we don''t need here.
Me![Item] = .Column(1)
End With
MsgBox Item & " is item here (yes)"

With Vendor
Me![Vendor] = .Column(1)
End With
MsgBox "is vendor here (no)" & Vendor

'' Find out if this supply is already on tblSupplies
PartNumber = Me.PartNumber

'' debug here
MsgBox " item: " & Item & " PN " & PartNumber & " Ven " & Vendor
intcount = DCount("[Item]", "tblSuppplies", "[Item] = " & Item And _
[PartNumber] = " & PartNumber And [Vendor] = " & Vendor)

'' For debugging:
MsgBox intcount

If intcount <> 0 Then
Err.Description = _
"This Supply-Part Number - Vendor is already on file. Please check
your entry."
GoTo Err_cmdAddItem_Click
Else

DoCmd.GoToRecord , , acNewRec

End If



请您修复DCount代码,但我甚至不能在代码中使用

。我没有得到供应商 -

我必须从(1)将项目更改为(0),我尝试与供应商 -

仍然没有运气。我收到了Obejct Variable或With Block Variable not

set"


就在我的MsgBox之前看到供应商。 ?供应商在

即时窗口中是空白的。


我喜欢多字段密钥的想法,但是我已经离开的用户组

表示供应ID应该是自动编号和唯一的密钥。我

如果Autonumber是关键的话,我不知道如何设置多字段密钥

(因此始终是唯一的)。我发现身份证/自动编号很有限,但是这些人比我有更多的经验,所以我试过了它的价格。


非常感谢您的帮助,指导和想法。

谢谢

Thnk you for fixing the DCount code, but I don''t even get that far in
the code. I don''t get the Vendor -
I had to change Item to (0) from (1), and I tried that with Vendor -
still no luck. I''m getting "Obejct Variable or With Block Variable not
set"

right before my MsgBox to see the vendor. ?Vendor is blank in the
immediate window.

I like the idea of the multiple field key, but a user group I have gone
to says that the "Supply ID" should be autonumber and the only key. I
don''t know how to set a multi-field key if the Autonumber is the key
(and therefore always unique). I find the ID/Autonumber quite
limiting, but these people have much more experience than I, so I tried
it.

Your help, guidance and thoughts are very much appreciated.
Thanks


> Set Item = Me.cboItem
> Set Item = Me.cboItem
With Item

与供应商
我![供应商] = .Column(1)
以$ b $结尾b

您会注意到错误信息是正确的,您没有将供应商设置为

您做了项目。通常,当您使用多个引用同一对象的语句时,将使用With语句来保存键入。在这种情况下,虽然

它会起作用,但我没有看到它能为你节省任何东西。另外,最后例行
,不要忘记将对象变量设置为Nothing。


示例:

Set Vendor = Nothing

Set Item = Nothing


多字段,唯一索引不一定是关键字段。您也可以手动设置

多字段索引。为此,请在设计视图中打开表格,然后

转到View | Indexes。在索引名称下,键入要用于此

索引的名称。它必须是唯一的名称,不要使用字段名称。在字段名称下,

输入三个字段中的第一个,根据需要设置排序顺序。在下一个

两行中,将索引名称留空,但填写字段名称并排序

其他两个字段的顺序。现在,回到第一行并在窗口的

底部设置Unique to Yes并关闭窗口。索引

最多可包含10个字段。


-

Wayne Morgan

MS访问MVP

" sara" < SA ****** @ yahoo.com>在消息中写道

新闻:11 ********************* @ f14g2000cwb.googlegro ups.com ...叮嘱你修复DCount代码,但我甚至没有在代码中获得那么多。我没有得到供应商 -
我不得不将商品从(1)更改为(0),我尝试与供应商合作 -
仍然没有运气。我在MsgBox之前找到Obejct Variable或With Block Variable not


来查看供应商。 ?供应商在
即时窗口中是空白的。

我喜欢多字段密钥的想法,但我已经去了一个用户组,说供应ID ;应该是自动编号和唯一的密钥。如果自动编号是关键的话,我不知道如何设置多字段键(因此始终是唯一的)。我觉得ID / Autonumber非常有限,但这些人比我有更多的经验,所以我尝试了它。

非常感谢你的帮助,指导和想法。
谢谢
With Item

With Vendor
Me![Vendor] = .Column(1)
End With
You will notice that the error message is correct, you haven''t Set vendor as
you did item. Usually, a With statement will be used to save typing when you
have multiple statements that refer to the same object. In this case, while
it will work, I don''t see that it is saving you anything. Also, at the end
of the routine, don''t forget to set your object variables to Nothing.

Example:
Set Vendor = Nothing
Set Item = Nothing

A multifield, unique index doesn''t have to be the key field. You can set a
multifield index manually also. To do so, open the table in design view and
go to View|Indexes. Under Index Name, type the name you want to use for this
index. It must be a unique name, don''t use a field name. Under Field Name,
enter the first of the three fields, set Sort Order as desired. In the next
two rows, leave the Index Name blank, but fill in the Field Name and Sort
Order for the other two fields. Now, go back to the first row and in the
bottom part of the window set Unique to Yes and close the window. An index
can contain up to ten fields.

--
Wayne Morgan
MS Access MVP
"sara" <sa******@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... Thnk you for fixing the DCount code, but I don''t even get that far in
the code. I don''t get the Vendor -
I had to change Item to (0) from (1), and I tried that with Vendor -
still no luck. I''m getting "Obejct Variable or With Block Variable not
set"

right before my MsgBox to see the vendor. ?Vendor is blank in the
immediate window.

I like the idea of the multiple field key, but a user group I have gone
to says that the "Supply ID" should be autonumber and the only key. I
don''t know how to set a multi-field key if the Autonumber is the key
(and therefore always unique). I find the ID/Autonumber quite
limiting, but these people have much more experience than I, so I tried
it.

Your help, guidance and thoughts are very much appreciated.
Thanks



这篇关于没有获得第二个组合框的值“with”声明&amp; Dcount帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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