【译文】如何允许用户为未绑定的组合框添加项目
时 间:2013-11-26 08:21:49
作 者:周芳 ID:24526 城市:上海
摘 要:如何允许用户为未绑定的组合框添加项目
正 文:
来自:微软 翻译:周芳
【译文】如何允许用户为未绑定的组合框添加项目
下面的例子使用了NotInList事件将一个条目添加到一个组合框。
尝试在这个示例中,在窗体中创建一个名为Colors(颜色)的组合框。组合框的LimitToList属性设置为Yes。 填充组合框,组合框的RowSourceType属性值列表,并为RowSource设置一个将列表的值用分号分隔的属性。例如,您可以提供以下值来设定这个属性:Red(红),Green(绿),Blue(蓝)。
接下来,为这个窗体添加以下事件过程。切换到窗体视图,输入一个新值到组合框的文本部分。
VBA代码:
Private Sub Colors_NotInList(NewData As String, _
Response As Integer)
Dim ctl As Control
' 返回指向组合框的控制对象.
Set ctl = Me!Colors
' 提示用户确认他们想添加的新值.
If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
' 当数据开始添加时设置一个回应.
Response = acDataErrAdded
' 为行来源的新数据连接成字符串.
ctl.RowSource = ctl.RowSource & ";" & NewData
Else
' 如果用户选择取消,废止出错信息并且取消更新.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
原文:How to: Allow Users to Add Items to an Unbound Combo Box
The following example uses the NotInList event to add an item to a combo box.
To try this example, create a combo box called Colors on a form. Set the combo box's LimitToList property to Yes. To populate the combo box, set the combo box's RowSourceType property to Value List, and supply a list of values separated by semicolons as the setting for the RowSource property. For example, you might supply the following values as the setting for this property: Red; Green; Blue.
Next, add the following event procedure to the form. Switch to Form view and enter a new value in the text portion of the combo box.
VBA
Private Sub Colors_NotInList(NewData As String, _
Response As Integer)
Dim ctl As Control
' Return Control object that points to combo box.
Set ctl = Me!Colors
' Prompt user to verify they want to add new value.
If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source.
ctl.RowSource = ctl.RowSource & ";" & NewData
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
原文:How to: Cancel the Deletion of a Record by Using Custom Criteria原文:How to: Cancel the Deletion of a Record by Using Custom Criteria原文:How to: Cancel the Deletion of a Record by Using Custom Criteria原文:How to: Cancel the Deletion of a Record by Using Custom Criteria
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- Inputbox输入密码打开查...(12.23)
- 【Access Dsum示例】...(12.16)
- Inputbox输入密码打开窗...(12.13)
- 【Access DCount示...(12.02)

学习心得
最新文章
- 用Access查询语句如何得到前3...(02.17)
- Access快速开发平台--导入导...(02.14)
- 按回车键后光标移动到下一条记录的V...(02.12)
- Access快速开发平台--要实现...(02.10)
- Access快速开发平台--让Pe...(02.08)
- 【Access Dsum示例】用D...(02.07)
- Access对子窗体的数据进行平均...(02.05)
- Access快速开发平台附件上传,...(01.18)
- 【IIF函数示例】用iif函数判断...(01.18)
- Access快速开发平台--如何获...(01.17)