组合框 - NotInList事件 - 需要帮助 [英] Combo Box - NotInList Event - need help

查看:100
本文介绍了组合框 - NotInList事件 - 需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我已经把自己描绘成了一个角落,我希望有人可以帮助我/ b
我了。


我有一个书籍表(tblBooks),其中包括一个字段(strPubName),用于

发布者名称和另一个发布者城市的字段(strPubCity)。这两个

字段与表有多对一的关系,(tlkpPubName和

tlkpPubCity)。查找表只有一个字段(strPubName

和strPubCity),这是它们的主键。


我还有一个包含两个字段的条目表: cbxPubName和cbxPubCity。


cbxPubName是RowSourceType" Table / Query"的组合框。和它的RowSource

是tlkpPubName。它的LimitToList属性为yes,它执行一个事件

过程,当OnNotInList事件发生时,将新条目添加到tlkpPubName。

cbxPubCity曾经以同样的方式工作(该事件程序的代码是

如下所示),直到我决定保存入门人(我)一些击键

通过减少基于发布商的城市选项。大多数出版商只有一个城市,但有些有两个。我所做的是设置cbxPubCity,它是'/ b
RowSource为:

SELECT tblBooks.strPubName,tblBooks.strPubCity FROM tblBooks GROUP BY

tblBooks.strPubName,tblBooks.strPubCity HAVING

(((tblBooks.strPubName)= Forms!frmBooks!cbxPubName));


这个工作得很好,直到我有一个新的publsher。那时,我可以输入

发布者,使用我的事件过程将其添加到列表中,但是因为我

正在根据可用城市构建cbxPubCity列表对于

特定的strPubName,cbxPubCity下拉列表中没有条目。

我陷入一个有意思的圈子,我必须从

列表,但我需要的条目永远不会出现,直到我可以保存记录

与其中的城市。


这是我的cbxPubCity OnNotInList事件的代码:


------------------------------ -------------------

Private Sub cbxPubCity_NotInList(NewData As String,响应为整数)


Dim db As DAO.Database,rst as DAO.Recordset


msg ="您输入的值不在列表中。 &安培; vbCrLf& 你想要

添加吗?


如果MsgBox(msg,vbYesNo + vbQuestion,Not in List)= vbYes Then

设置db = CurrentDb

''打开包含RowSource数据的记录集

设置rst = db.OpenRecordset(" tlkpPubCity")

''将新数据添加到记录集

rst

.AddNew

!strPubCity = NewData' '添加数据。

。更新''保存更改。

。关闭

结束

''告诉访问你添加了一个新项目

响应= acDataErrAdded


否则

''如果在MsgBox中选择了No,那么告诉

''访问你不想要新项目

响应= acDataErrContinue

Me.cbxPubCity.Undo

结束如果

''自己清理

Set rst = Nothing

设置db = Nothing


End Sub

----------------- -----------------------------------------


(很久以前有人帮助我使用了这段代码!)我觉得应该有一些相当简单的东西可以在else之前完成。条款,

但我不确定是什么。


我会推荐任何建议。谢谢。


Alice

-

图书收藏条款。偶尔出售的书籍。
http://www.mywingsbooks.com/

I think I''ve painted myself into a corner, and I''m hoping someone can help
me out.

I have a table of books (tblBooks), which includes a field (strPubName) for
Publisher Name and another field (strPubCity) for Publisher City. These two
fields have a many-to-one relationship with tables, (tlkpPubName and
tlkpPubCity) respectively. The lookup tables only have one field (strPubName
and strPubCity), which is their primary key.

I also have an entry form which has two fields: cbxPubName and cbxPubCity.

cbxPubName is a combo box of RowSourceType "Table/Query" and its RowSource
is tlkpPubName. Its LimitToList property is "yes", and it executes an event
procedure to add new entries to tlkpPubName when the OnNotInList event
occurs.

cbxPubCity used to work the same way (code for that event procedures is
shown below), until I decided to save the entry person (me) some keystrokes
by reducing the city options based on a publisher. Most publishers have only
one city, although some have two. What I did was set cbxPubCity up with it''s
RowSource as:

SELECT tblBooks.strPubName, tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName, tblBooks.strPubCity HAVING
(((tblBooks.strPubName)=Forms!frmBooks!cbxPubName) );

This worked great until I had a new publsher. At that point, I could enter
the publisher, adding it to the list with my Event Procedure, but since I
was building the list for cbxPubCity based on the cities available for a
specific strPubName, there were no entries in the cbxPubCity drop down list.
I am caught in a viscious circle where I have to pick something from the
list, but the entry I need will never show up until I can save the record
with the city in it.

Here is my code for the cbxPubCity OnNotInList event:

-------------------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database, rst As DAO.Recordset

msg = "You have entered a value not in the list." & vbCrLf & "Do you want to
add it?"

If MsgBox(msg, vbYesNo + vbQuestion, "Not in List") = vbYes Then
Set db = CurrentDb
''Open the recordset that has the RowSource data
Set rst = db.OpenRecordset("tlkpPubCity")
''Add the new data to the recordset
With rst
.AddNew
!strPubCity = NewData ''Add data.
.Update ''Save changes.
.Close
End With
''Tells Access you added a new item
Response = acDataErrAdded

Else
''If No was chosen in the MsgBox then tell
''Access you didn''t want the new item
Response = acDataErrContinue
Me.cbxPubCity.Undo

End If
''Clean up after yourself
Set rst = Nothing
Set db = Nothing

End Sub
----------------------------------------------------------

(Someone here helped me with that code long ago!) I feel there should be
something fairly simple that could be done right before the "else" clause,
but I''m not sure what.

I would apprecaite any suggestions. Thanks.

Alice
--
Book collecting terms illustrated. Occasional books for sale.
http://www.mywingsbooks.com/

推荐答案

my-wings写道:
my-wings wrote:
我想我已经把自己描绘成了一个角落,我''我希望有人能帮助我。

我有一个书桌(tblBooks),其中包括一个字段(strPubName),用于
Publisher Name和另一个字段(strPubCity)对于Publisher City。这两个
字段分别与表(tlkpPubName和
tlkpPubCity)有多对一的关系。查找表只有一个字段(strPubName
和strPubCity),这是它们的主键。

我还有一个输入表单,它有两个字段:cbxPubName和cbxPubCity。

cbxPubName是RowSourceType" Table / Query"的组合框。它的RowSource
是tlkpPubName。它的LimitToList属性为yes,它执行一个事件
过程,当OnNotInList事件发生时,将新条目添加到tlkpPubName。

cbxPubCity过去以相同的方式工作(该事件程序的代码如下所示),直到我决定通过减少基于出版商的城市选项来保存入门人员(我)一些击键
。大多数出版商只有一个城市,但有些有两个城市。我所做的是将cbxPubCity设置为它的RowSource为:

SELECT tblBooks.strPubName,tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName,tblBooks.strPubCity HAVING
(((tblBooks.strPubName)= Forms!frmBooks!cbxPubName));

这个很有用,直到我有了一个新的publsher。此时,我可以输入发布者,使用我的事件过程将其添加到列表中,但是因为我正在构建基于可用于特定strPubName的城市的cbxPubCity列表,cbxPubCity下拉列表中没有条目。
我陷入了一个有意思的圈子,我必须从
列表中选择一些东西,但是我需要的条目在我保存之前永远不会出现记录
与城市在一起。

这是我的cbxPubCity OnNotInList事件的代码:

------------ -------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String,Response作为整数)

Dim db As DAO.Database,rst as DAO.Recordset

msg ="您输入的值不在列表中。 &安培; vbCrLf& 你想要添加它吗?

如果MsgBox(msg,vbYesNo + vbQuestion,Not in List)= vbYes那么
设置db = CurrentDb
''打开包含RowSource数据的记录集
Set rst = db.OpenRecordset(" tlkpPubCity")
''将新数据添加到记录集
使用rst
.AddNew
!strPubCity = NewData''添加数据。
。更新''保存更改。
。关闭
结束
''告诉访问你添加了一个新项目
响应= acDataErrAdded

其他
''如果在MsgBox中选择了No,那么告诉
''访问你不想要新的item
响应= acDataErrContinue
Me.cbxPubCity.Undo

结束如果
''自己清理
设置rst = Nothing
设置db = Nothing

End Sub
--------------------------------- -------------------------

(很久以前有人在这里帮我解决了这个问题!)我觉得应该有一些相当简单的东西可以在其他之前完成。条款,
但我不确定是什么。

我会建议任何建议。谢谢。

Alice
I think I''ve painted myself into a corner, and I''m hoping someone can help
me out.

I have a table of books (tblBooks), which includes a field (strPubName) for
Publisher Name and another field (strPubCity) for Publisher City. These two
fields have a many-to-one relationship with tables, (tlkpPubName and
tlkpPubCity) respectively. The lookup tables only have one field (strPubName
and strPubCity), which is their primary key.

I also have an entry form which has two fields: cbxPubName and cbxPubCity.

cbxPubName is a combo box of RowSourceType "Table/Query" and its RowSource
is tlkpPubName. Its LimitToList property is "yes", and it executes an event
procedure to add new entries to tlkpPubName when the OnNotInList event
occurs.

cbxPubCity used to work the same way (code for that event procedures is
shown below), until I decided to save the entry person (me) some keystrokes
by reducing the city options based on a publisher. Most publishers have only
one city, although some have two. What I did was set cbxPubCity up with it''s
RowSource as:

SELECT tblBooks.strPubName, tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName, tblBooks.strPubCity HAVING
(((tblBooks.strPubName)=Forms!frmBooks!cbxPubName) );

This worked great until I had a new publsher. At that point, I could enter
the publisher, adding it to the list with my Event Procedure, but since I
was building the list for cbxPubCity based on the cities available for a
specific strPubName, there were no entries in the cbxPubCity drop down list.
I am caught in a viscious circle where I have to pick something from the
list, but the entry I need will never show up until I can save the record
with the city in it.

Here is my code for the cbxPubCity OnNotInList event:

-------------------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database, rst As DAO.Recordset

msg = "You have entered a value not in the list." & vbCrLf & "Do you want to
add it?"

If MsgBox(msg, vbYesNo + vbQuestion, "Not in List") = vbYes Then
Set db = CurrentDb
''Open the recordset that has the RowSource data
Set rst = db.OpenRecordset("tlkpPubCity")
''Add the new data to the recordset
With rst
.AddNew
!strPubCity = NewData ''Add data.
.Update ''Save changes.
.Close
End With
''Tells Access you added a new item
Response = acDataErrAdded

Else
''If No was chosen in the MsgBox then tell
''Access you didn''t want the new item
Response = acDataErrContinue
Me.cbxPubCity.Undo

End If
''Clean up after yourself
Set rst = Nothing
Set db = Nothing

End Sub
----------------------------------------------------------

(Someone here helped me with that code long ago!) I feel there should be
something fairly simple that could be done right before the "else" clause,
but I''m not sure what.

I would apprecaite any suggestions. Thanks.

Alice




如果根据这个

是否为一个将LimitToList设置为false会发生什么?是不是有新纪录?



What happens if you set the LimitToList to false based upon whether this
is a new record or not?


my-wings写道:
my-wings wrote:
我想我已经把自己画成了一个角落,我希望有人可以帮助我。

我有一个书桌(tblBooks),其中包括一个字段(strPubName),用于
Publisher Name和另一个字段发布商城的(strPubCity)。这两个
字段分别与表(tlkpPubName和
tlkpPubCity)有多对一的关系。查找表只有一个字段(strPubName
和strPubCity),这是它们的主键。

我还有一个输入表单,它有两个字段:cbxPubName和cbxPubCity。

cbxPubName是RowSourceType" Table / Query"的组合框。它的RowSource
是tlkpPubName。它的LimitToList属性为yes,它执行一个事件
过程,当OnNotInList事件发生时,将新条目添加到tlkpPubName。

cbxPubCity过去以相同的方式工作(该事件程序的代码如下所示),直到我决定通过减少基于出版商的城市选项来保存入门人员(我)一些击键
。大多数出版商只有一个城市,但有些有两个城市。我所做的是将cbxPubCity设置为它的RowSource为:

SELECT tblBooks.strPubName,tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName,tblBooks.strPubCity HAVING
(((tblBooks.strPubName)= Forms!frmBooks!cbxPubName));

这个很有用,直到我有了一个新的publsher。此时,我可以输入发布者,使用我的事件过程将其添加到列表中,但是因为我正在构建基于可用于特定strPubName的城市的cbxPubCity列表,cbxPubCity下拉列表中没有条目。
我陷入了一个有意思的圈子,我必须从
列表中选择一些东西,但是我需要的条目在我保存之前永远不会出现记录
与城市在一起。

这是我的cbxPubCity OnNotInList事件的代码:

------------ -------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String,Response作为整数)

Dim db As DAO.Database,rst as DAO.Recordset

msg ="您输入的值不在列表中。 &安培; vbCrLf& 你想要添加它吗?

如果MsgBox(msg,vbYesNo + vbQuestion,Not in List)= vbYes那么
设置db = CurrentDb
''打开包含RowSource数据的记录集
Set rst = db.OpenRecordset(" tlkpPubCity")
''将新数据添加到记录集
使用rst
.AddNew
!strPubCity = NewData''添加数据。
。更新''保存更改。
。关闭
结束
''告诉访问你添加了一个新项目
响应= acDataErrAdded

其他
''如果在MsgBox中选择了No,那么告诉
''访问你不想要新的item
响应= acDataErrContinue
Me.cbxPubCity.Undo

结束如果
''自己清理
设置rst = Nothing
设置db = Nothing

End Sub
--------------------------------- -------------------------

(很久以前有人在这里帮我解决了这个问题!)我觉得应该有一些相当简单的东西可以在其他之前完成。条款,
但我不确定是什么。

我会建议任何建议。谢谢。

Alice
I think I''ve painted myself into a corner, and I''m hoping someone can help
me out.

I have a table of books (tblBooks), which includes a field (strPubName) for
Publisher Name and another field (strPubCity) for Publisher City. These two
fields have a many-to-one relationship with tables, (tlkpPubName and
tlkpPubCity) respectively. The lookup tables only have one field (strPubName
and strPubCity), which is their primary key.

I also have an entry form which has two fields: cbxPubName and cbxPubCity.

cbxPubName is a combo box of RowSourceType "Table/Query" and its RowSource
is tlkpPubName. Its LimitToList property is "yes", and it executes an event
procedure to add new entries to tlkpPubName when the OnNotInList event
occurs.

cbxPubCity used to work the same way (code for that event procedures is
shown below), until I decided to save the entry person (me) some keystrokes
by reducing the city options based on a publisher. Most publishers have only
one city, although some have two. What I did was set cbxPubCity up with it''s
RowSource as:

SELECT tblBooks.strPubName, tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName, tblBooks.strPubCity HAVING
(((tblBooks.strPubName)=Forms!frmBooks!cbxPubName) );

This worked great until I had a new publsher. At that point, I could enter
the publisher, adding it to the list with my Event Procedure, but since I
was building the list for cbxPubCity based on the cities available for a
specific strPubName, there were no entries in the cbxPubCity drop down list.
I am caught in a viscious circle where I have to pick something from the
list, but the entry I need will never show up until I can save the record
with the city in it.

Here is my code for the cbxPubCity OnNotInList event:

-------------------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database, rst As DAO.Recordset

msg = "You have entered a value not in the list." & vbCrLf & "Do you want to
add it?"

If MsgBox(msg, vbYesNo + vbQuestion, "Not in List") = vbYes Then
Set db = CurrentDb
''Open the recordset that has the RowSource data
Set rst = db.OpenRecordset("tlkpPubCity")
''Add the new data to the recordset
With rst
.AddNew
!strPubCity = NewData ''Add data.
.Update ''Save changes.
.Close
End With
''Tells Access you added a new item
Response = acDataErrAdded

Else
''If No was chosen in the MsgBox then tell
''Access you didn''t want the new item
Response = acDataErrContinue
Me.cbxPubCity.Undo

End If
''Clean up after yourself
Set rst = Nothing
Set db = Nothing

End Sub
----------------------------------------------------------

(Someone here helped me with that code long ago!) I feel there should be
something fairly simple that could be done right before the "else" clause,
but I''m not sure what.

I would apprecaite any suggestions. Thanks.

Alice




例如

me.Combo0.LimitToList =(Not Me.NewRecord)



Such as
me.Combo0.LimitToList = (Not Me.NewRecord)


my-wings写道:
my-wings wrote:
我想我已经把自己画成了一个角落,而且我我希望有人能帮助我。

我有一个书桌(tblBooks),其中包括一个字段(strPubName),用于
Publisher Name和另一个字段(strPubCity) )对于发布者城市。这两个
字段分别与表(tlkpPubName和
tlkpPubCity)有多对一的关系。查找表只有一个字段(strPubName
和strPubCity),这是它们的主键。

我还有一个输入表单,它有两个字段:cbxPubName和cbxPubCity。

cbxPubName是RowSourceType" Table / Query"的组合框。它的RowSource
是tlkpPubName。它的LimitToList属性为yes,它执行一个事件
过程,当OnNotInList事件发生时,将新条目添加到tlkpPubName。

cbxPubCity过去以相同的方式工作(该事件程序的代码如下所示),直到我决定通过减少基于出版商的城市选项来保存入门人员(我)一些击键
。大多数出版商只有一个城市,但有些有两个城市。我所做的是将cbxPubCity设置为它的RowSource为:

SELECT tblBooks.strPubName,tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName,tblBooks.strPubCity HAVING
(((tblBooks.strPubName)= Forms!frmBooks!cbxPubName));

这个很有用,直到我有了一个新的publsher。此时,我可以输入发布者,使用我的事件过程将其添加到列表中,但是因为我正在构建基于可用于特定strPubName的城市的cbxPubCity列表,cbxPubCity下拉列表中没有条目。
我陷入了一个有意思的圈子,我必须从
列表中选择一些东西,但是我需要的条目在我保存之前永远不会出现记录
与城市在一起。

这是我的cbxPubCity OnNotInList事件的代码:

------------ -------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String,Response作为整数)

Dim db As DAO.Database,rst as DAO.Recordset

msg ="您输入的值不在列表中。 &安培; vbCrLf& 你想要添加它吗?

如果MsgBox(msg,vbYesNo + vbQuestion,Not in List)= vbYes那么
设置db = CurrentDb
''打开包含RowSource数据的记录集
Set rst = db.OpenRecordset(" tlkpPubCity")
''将新数据添加到记录集
使用rst
.AddNew
!strPubCity = NewData''添加数据。
。更新''保存更改。
。关闭
结束
''告诉访问你添加了一个新项目
响应= acDataErrAdded

其他
''如果在MsgBox中选择了No,那么告诉
''访问你不想要新的item
响应= acDataErrContinue
Me.cbxPubCity.Undo

结束如果
''自己清理
设置rst = Nothing
设置db = Nothing

End Sub
--------------------------------- -------------------------

(很久以前有人在这里帮我解决了这个问题!)我觉得应该有一些相当简单的东西可以在其他之前完成。条款,
但我不确定是什么。

我会建议任何建议。谢谢。

Alice
I think I''ve painted myself into a corner, and I''m hoping someone can help
me out.

I have a table of books (tblBooks), which includes a field (strPubName) for
Publisher Name and another field (strPubCity) for Publisher City. These two
fields have a many-to-one relationship with tables, (tlkpPubName and
tlkpPubCity) respectively. The lookup tables only have one field (strPubName
and strPubCity), which is their primary key.

I also have an entry form which has two fields: cbxPubName and cbxPubCity.

cbxPubName is a combo box of RowSourceType "Table/Query" and its RowSource
is tlkpPubName. Its LimitToList property is "yes", and it executes an event
procedure to add new entries to tlkpPubName when the OnNotInList event
occurs.

cbxPubCity used to work the same way (code for that event procedures is
shown below), until I decided to save the entry person (me) some keystrokes
by reducing the city options based on a publisher. Most publishers have only
one city, although some have two. What I did was set cbxPubCity up with it''s
RowSource as:

SELECT tblBooks.strPubName, tblBooks.strPubCity FROM tblBooks GROUP BY
tblBooks.strPubName, tblBooks.strPubCity HAVING
(((tblBooks.strPubName)=Forms!frmBooks!cbxPubName) );

This worked great until I had a new publsher. At that point, I could enter
the publisher, adding it to the list with my Event Procedure, but since I
was building the list for cbxPubCity based on the cities available for a
specific strPubName, there were no entries in the cbxPubCity drop down list.
I am caught in a viscious circle where I have to pick something from the
list, but the entry I need will never show up until I can save the record
with the city in it.

Here is my code for the cbxPubCity OnNotInList event:

-------------------------------------------------
Private Sub cbxPubCity_NotInList(NewData As String, Response As Integer)

Dim db As DAO.Database, rst As DAO.Recordset

msg = "You have entered a value not in the list." & vbCrLf & "Do you want to
add it?"

If MsgBox(msg, vbYesNo + vbQuestion, "Not in List") = vbYes Then
Set db = CurrentDb
''Open the recordset that has the RowSource data
Set rst = db.OpenRecordset("tlkpPubCity")
''Add the new data to the recordset
With rst
.AddNew
!strPubCity = NewData ''Add data.
.Update ''Save changes.
.Close
End With
''Tells Access you added a new item
Response = acDataErrAdded

Else
''If No was chosen in the MsgBox then tell
''Access you didn''t want the new item
Response = acDataErrContinue
Me.cbxPubCity.Undo

End If
''Clean up after yourself
Set rst = Nothing
Set db = Nothing

End Sub
----------------------------------------------------------

(Someone here helped me with that code long ago!) I feel there should be
something fairly simple that could be done right before the "else" clause,
but I''m not sure what.

I would apprecaite any suggestions. Thanks.

Alice




忘了另一件事。您可能还想更改

组合的SQL行数。



Forgot another thing. You might want to change the SQL rowsource for
the combo too.


这篇关于组合框 - NotInList事件 - 需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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