【译文】如何允许用户为未绑定的组合框添加项目
时 间: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)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)
- Access快速开发平台--让有权...(11.04)
- Access快速开发平台--审批选...(11.01)
- ACCESS两张表先各自排序,然后...(10.31)
- Access对子窗体数据进行批量+...(10.30)
- SqlServer中如何用SQL命...(10.29)
- Access报表中的分组功能用代码...(10.28)
- 用Access计算库存结余的一个方...(10.26)
- 最精简的组合框行来源数据快速输入(...(10.25)