PC Review


Reply
Thread Tools Rate Thread

Cancel NotInList Error

 
 
David C. Holley
Guest
Posts: n/a
 
      22nd Feb 2005
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
 
Reply With Quote
 
 
 
 
John Spencer (MVP)
Guest
Posts: n/a
 
      23rd Feb 2005
Try using the constant acDataErrAdded in place of Data_ErrAdded and
acDataErrContinue for Data_ErrContinue

"David C. Holley" wrote:
>
> 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

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      23rd Feb 2005
Still getting the message 'THE TEXT YOU ENTERED ISN'T AN ITEM IN THE LIST.'

David H

John Spencer (MVP) wrote:
> Try using the constant acDataErrAdded in place of Data_ErrAdded and
> acDataErrContinue for Data_ErrContinue
>
> "David C. Holley" wrote:
>
>>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

 
Reply With Quote
 
John Spencer (MVP)
Guest
Posts: n/a
 
      24th Feb 2005
Hmm, are you using the correct constant in the correct place. If you add a new
item then you should be setting "Response" to acDataErrAdded. If you are not
adding data and you have handled the error in your code, then you should be
setting "Response: to acDataErrContinue.

I apologize for not examining your code more closely.

"David C. Holley" wrote:
>
> Still getting the message 'THE TEXT YOU ENTERED ISN'T AN ITEM IN THE LIST.'
>
> David H
>
> John Spencer (MVP) wrote:
> > Try using the constant acDataErrAdded in place of Data_ErrAdded and
> > acDataErrContinue for Data_ErrContinue
> >
> > "David C. Holley" wrote:
> >
> >>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

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      24th Feb 2005
Minus the initial IF...THEN which does the lookup, the code works as-is.

John Spencer (MVP) wrote:
> Hmm, are you using the correct constant in the correct place. If you add a new
> item then you should be setting "Response" to acDataErrAdded. If you are not
> adding data and you have handled the error in your code, then you should be
> setting "Response: to acDataErrContinue.
>
> I apologize for not examining your code more closely.
>
> "David C. Holley" wrote:
>
>>Still getting the message 'THE TEXT YOU ENTERED ISN'T AN ITEM IN THE LIST.'
>>
>>David H
>>
>>John Spencer (MVP) wrote:
>>
>>>Try using the constant acDataErrAdded in place of Data_ErrAdded and
>>>acDataErrContinue for Data_ErrContinue
>>>
>>>"David C. Holley" wrote:
>>>
>>>
>>>>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

 
Reply With Quote
 
David C. Holley
Guest
Posts: n/a
 
      25th Feb 2005
The problem was that I was using the wrong value for the response in the
initial IF..THEN, after consulting Access Help*, I realized that
acDataErrContinue would do the trick. I will NEVER complain about people
complaining about legacy code - the original routine was written nearly
seven years ago.

David H
*Never thought that Help in a Microsoft product would actually be helpful.

David C. Holley wrote:
> Minus the initial IF...THEN which does the lookup, the code works as-is.
>
> John Spencer (MVP) wrote:
>
>> Hmm, are you using the correct constant in the correct place. If you
>> add a new
>> item then you should be setting "Response" to acDataErrAdded. If you
>> are not
>> adding data and you have handled the error in your code, then you
>> should be
>> setting "Response: to acDataErrContinue.
>> I apologize for not examining your code more closely.
>> "David C. Holley" wrote:
>>
>>> Still getting the message 'THE TEXT YOU ENTERED ISN'T AN ITEM IN THE
>>> LIST.'
>>>
>>> David H
>>>
>>> John Spencer (MVP) wrote:
>>>
>>>> Try using the constant acDataErrAdded in place of Data_ErrAdded and
>>>> acDataErrContinue for Data_ErrContinue
>>>>
>>>> "David C. Holley" wrote:
>>>>
>>>>
>>>>> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cancel NotInList event Hugh self taught Microsoft Access Form Coding 1 2nd Apr 2010 03:36 PM
NotInList Error Problem =?Utf-8?B?UGV0ZQ==?= Microsoft Access Form Coding 3 26th Jun 2007 08:10 AM
NotInList error msg =?Utf-8?B?RGVs?= Microsoft Access VBA Modules 3 25th Apr 2007 06:04 PM
NotInList Error =?Utf-8?B?QXJpYQ==?= Microsoft Access Form Coding 5 23rd Mar 2005 12:04 AM
NotInList error for new entries =?Utf-8?B?UmVubyBMaW5kYmVyZw==?= Microsoft Access Form Coding 7 4th Jan 2004 12:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:43 AM.