Hello everyone,
I have a combo box that is "Limited to List". When the User enters an item not on the list, a message asks "Do you want to add this to the list?"
If the User Clicks "Yes", the item it added to the list and the field will contain the new item.
If the User Clicks "No", a message tells them they must select an item from the list.
HERE's WHERE I NEED HELP: The Users would like to be able to Click "No" and enter their new item in the field and not have it saved in the List.
Here's my code, in the "On Not In List" Event:
Private Sub cboVendor_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cboVendor_NotInList
' From Access 2000 Developer's Handbook, Volume I
' by Getz, Litwin, and Gilbert (Sybex)
' Copyright 1999. All rights reserved.
' Amended by P. Stroud on 03/06/2008
' EOP Budget and Fiscal database - VISA Statement
' Add new items to the table/field: tblVendors.VendorName
Dim strMsg As String
#If USEDAO Then
Dim rst As DAO.Recordset
Dim db As DAO.Database
#Else
Dim rst As ADODB.Recordset
#End If
strMsg = "'" & NewData & "' is not in the list. "
strMsg = strMsg & "Would you like to add it?"
If vbNo = MsgBox(strMsg, vbYesNo + vbQuestion, _
"New Vendor") Then
Response = acDataErrDisplay
Else
#If USEDAO Then
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblVendors")
#Else
Set rst = New ADODB.Recordset
rst.Open _
Source:="tblVendors", _
ActiveConnection:=CurrentProject.Connection, _
CursorType:=adOpenKeyset, _
LockType:=adLockOptimistic, _
Options:=adCmdTableDirect
#End If
rst.AddNew
rst("VendorName") = NewData
rst.Update
Response = acDataErrAdded
rst.Close
End If
Exit_cboVendor_NotInList:
Exit Sub
Err_cboVendor_NotInList:
MsgBox Err.Number & " " & Err.Description
Resume Exit_cboVendor_NotInList
End Sub
I have a combo box that is "Limited to List". When the User enters an item not on the list, a message asks "Do you want to add this to the list?"
If the User Clicks "Yes", the item it added to the list and the field will contain the new item.
If the User Clicks "No", a message tells them they must select an item from the list.
HERE's WHERE I NEED HELP: The Users would like to be able to Click "No" and enter their new item in the field and not have it saved in the List.
Here's my code, in the "On Not In List" Event:
Private Sub cboVendor_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cboVendor_NotInList
' From Access 2000 Developer's Handbook, Volume I
' by Getz, Litwin, and Gilbert (Sybex)
' Copyright 1999. All rights reserved.
' Amended by P. Stroud on 03/06/2008
' EOP Budget and Fiscal database - VISA Statement
' Add new items to the table/field: tblVendors.VendorName
Dim strMsg As String
#If USEDAO Then
Dim rst As DAO.Recordset
Dim db As DAO.Database
#Else
Dim rst As ADODB.Recordset
#End If
strMsg = "'" & NewData & "' is not in the list. "
strMsg = strMsg & "Would you like to add it?"
If vbNo = MsgBox(strMsg, vbYesNo + vbQuestion, _
"New Vendor") Then
Response = acDataErrDisplay
Else
#If USEDAO Then
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblVendors")
#Else
Set rst = New ADODB.Recordset
rst.Open _
Source:="tblVendors", _
ActiveConnection:=CurrentProject.Connection, _
CursorType:=adOpenKeyset, _
LockType:=adLockOptimistic, _
Options:=adCmdTableDirect
#End If
rst.AddNew
rst("VendorName") = NewData
rst.Update
Response = acDataErrAdded
rst.Close
End If
Exit_cboVendor_NotInList:
Exit Sub
Err_cboVendor_NotInList:
MsgBox Err.Number & " " & Err.Description
Resume Exit_cboVendor_NotInList
End Sub