【译文】如何允许用户为未绑定的组合框添加项目
时 间: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)
- Access制作的RGB转CM...(09.22)
- Access制作的RGB调色板...(09.15)
- Access制作的快速车牌输入...(09.13)
- 【Access高效办公】统计当...(06.30)
- 【Access高效办公】用复选...(06.24)
- 根据变化的日期来自动编号的示例...(06.20)
- 【Access高效办公】按日期...(06.12)
- 合并列数据到一个文本框的示例;...(05.06)
 
  学习心得
最新文章
- 【Access高效办公】上一年度累...(10.30)
- Access做的一个《中华经典论语...(10.25)
- Access快速开发平台--加载事...(10.20)
- 【Access有效性规则示例】两种...(10.10)
- EXCEL表格扫描枪数据录入智能处...(10.09)
- Access快速开发平台--多行文...(09.28)
- 关于从Excel导入长文本数据到A...(09.24)
- Access制作的RGB转CMYK...(09.22)
- 关于重装系统后Access开发的软...(09.17)
- Access制作的RGB调色板示例(09.15)
 

 
  
.gif)

 
            