查阅列表数据维护的功能详细请查询看快速平台帮助页面
http://www.accessgood.com/help/LookupList.html
我们再做好组合框后想对不在列表框中的数据进行快速添加,那我们只需要在该组合框的不在列表中的事件里下写如下的代码:
Private Sub 组合框名_NotInList(NewData As String, Response As Integer)
AddItemToList Me.组合框名, "在查阅数据列表中的名称", NewData, Response
End Sub
下面的函数放到模块:
Function AddItemToList(Combo As ComboBox, ByVal ItemName As String, NewData As String, Response As Integer)
Dim lngOrder As Long
Response = acDataErrContinue
ItemName = Replace(ItemName, "'", "''")
Beep
If MsgBox("输入的值在列表中不存在,是否自动添加到列表?", vbQuestion + vbYesNo, "提示") = vbYes Then
Combo.Undo
If DCount("*", "Sys_LookupList", "Item='" & ItemName & "'") = 0 Then
CurrentDb.Execute "Insert INTO Sys_LookupList([Item],[Value]) VALUES('" & ItemName & "','')"
End If
CurrentDb.Execute "Insert INTO Sys_LookupList([Item],[value]) VALUES('" & ItemName & "','" & NewData & "')"
Combo.Requery
Combo = NewData
Else
Combo.Undo
MsgBox "必须从列表中选择一个值。", vbInformation, "提示"
End If
End Function