Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > 综合其它

【译文】如何允许用户为未绑定的组合框添加项目

时 间: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源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助