【译文】如何允许用户为未绑定的组合框添加项目-周芳
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


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

发表时间:2013/11/26 8:21:49 评论(1) 浏览(7363)  评论 | 加入收藏 | 复制
   
摘 要:如何允许用户为未绑定的组合框添加项目 
正 文:

来自:微软  翻译:周芳

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

 

      下面的例子使用了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群(群号:198465573)
 
 相关文章
【译文】如果主窗体不包含记录,如何隐藏它的子窗体  【周芳  2013/9/10】
【译文】如何判断当前的记录在窗体里是否是一个新记录  【周芳  2013/10/18】
【译文】如何在保存一个记录前提示用户  【周芳  2013/10/29】
【译文】如何:提示用户在窗体中编辑数据前对数据的有效性确认  【周芳  2013/11/5】
【译文】如何使用自定义条件删除记录  【周芳  2013/11/19】
常见问答
技术分类
相关资源
文章搜索
关于作者

周芳

文章分类

文章存档

友情链接