D
David C. Holley
The following code is attached to the OnNotInList Event of a combo box
that I have. The idea behind the code is to check wether or not the
value entered exists in a field DIFFERENT from the bound filed of the
combo box. The idea is that if I want to select DAVID C. HOLLEY, I can
enter dch3 (lan ID) and the comboBox would automatically be set to DAVID
C. HOLLEY. Since dch3 is not in the list and the LimitToList is set to
true, the OnNotInList fires which it should to allow a new name to be
entered. The function as originally written (without the initial If
DCount() then... statement) works, the problem is that once the value is
pulled from the table and put in the comboBox, Access returns an error
message that the value is not in the list.
How can I tell Access to ignore the error and supress the error message?
I tried Err.Clear, but the message persists?
FYI - The code was pulled from an example in Access help from a few
versions ago.
David H
Private Sub cboOrigination_NotInList(NewData As String, response As Integer)
On Error GoTo Err_cboOrigination_NotInList
If DCount("txtPPCLocationAlias", "tblLocations",
"[txtPPCLocationAlias] = '" & NewData & "'") = 1 Then
[Forms]![frmReservations]![cboOrigination] =
DLookup("txtLocationName", "tblLocations", "[txtPPCLocationAlias] = '" &
"'")
response = DATA_ERRADDED
Exit Sub
Else
MsgText = ""
MsgText = MsgText & "The location entered has not been" &
Chr$(10) & Chr$(13)
MsgText = MsgText & "set-up for use in the database. " &
Chr$(10) & Chr$(13)
MsgText = MsgText & "Do you want to add the location?"
If MsgBox(MsgText, 324) = 7 Then
MsgText = "Please select a location from the list."
MsgBox MsgText, 64
response = DATA_ERRCONTINUE
GoTo Exit_cboOrigination_NotInList
End If
DoCmd.Echo False
DoCmd.OpenForm "frmLocations", , , , A_ADD, A_DIALOG, Me.Name
DoCmd.Echo True
If [Forms]![frmReservations]![response] = DATA_ERRADDED Then
'Test if a new record has been added
'Set the combo box here
[Forms]![frmReservations]![response] = DATA_ERRCONTINUE
response = DATA_ERRADDED
[Forms]![frmReservations]![cboDestination].Requery
Exit Sub
End If
MsgText = "Please select a location from the list."
MsgBox MsgText, 64
response = DATA_ERRCONTINUE
Exit Sub
End If
Exit_cboOrigination_NotInList:
DoCmd.Hourglass False
[Forms]![frmReservations]![response] = DATA_ERRCONTINUE
Exit Sub
Err_cboOrigination_NotInList:
Exit Sub
End Sub
that I have. The idea behind the code is to check wether or not the
value entered exists in a field DIFFERENT from the bound filed of the
combo box. The idea is that if I want to select DAVID C. HOLLEY, I can
enter dch3 (lan ID) and the comboBox would automatically be set to DAVID
C. HOLLEY. Since dch3 is not in the list and the LimitToList is set to
true, the OnNotInList fires which it should to allow a new name to be
entered. The function as originally written (without the initial If
DCount() then... statement) works, the problem is that once the value is
pulled from the table and put in the comboBox, Access returns an error
message that the value is not in the list.
How can I tell Access to ignore the error and supress the error message?
I tried Err.Clear, but the message persists?
FYI - The code was pulled from an example in Access help from a few
versions ago.
David H
Private Sub cboOrigination_NotInList(NewData As String, response As Integer)
On Error GoTo Err_cboOrigination_NotInList
If DCount("txtPPCLocationAlias", "tblLocations",
"[txtPPCLocationAlias] = '" & NewData & "'") = 1 Then
[Forms]![frmReservations]![cboOrigination] =
DLookup("txtLocationName", "tblLocations", "[txtPPCLocationAlias] = '" &
"'")
response = DATA_ERRADDED
Exit Sub
Else
MsgText = ""
MsgText = MsgText & "The location entered has not been" &
Chr$(10) & Chr$(13)
MsgText = MsgText & "set-up for use in the database. " &
Chr$(10) & Chr$(13)
MsgText = MsgText & "Do you want to add the location?"
If MsgBox(MsgText, 324) = 7 Then
MsgText = "Please select a location from the list."
MsgBox MsgText, 64
response = DATA_ERRCONTINUE
GoTo Exit_cboOrigination_NotInList
End If
DoCmd.Echo False
DoCmd.OpenForm "frmLocations", , , , A_ADD, A_DIALOG, Me.Name
DoCmd.Echo True
If [Forms]![frmReservations]![response] = DATA_ERRADDED Then
'Test if a new record has been added
'Set the combo box here
[Forms]![frmReservations]![response] = DATA_ERRCONTINUE
response = DATA_ERRADDED
[Forms]![frmReservations]![cboDestination].Requery
Exit Sub
End If
MsgText = "Please select a location from the list."
MsgBox MsgText, 64
response = DATA_ERRCONTINUE
Exit Sub
End If
Exit_cboOrigination_NotInList:
DoCmd.Hourglass False
[Forms]![frmReservations]![response] = DATA_ERRCONTINUE
Exit Sub
Err_cboOrigination_NotInList:
Exit Sub
End Sub