Solved

How can cancel a Not on List error in a combo box?

Posted on 2011-02-22
18
348 Views
Last Modified: 2012-06-27
I have a combo box that has a control source called casestatus. If a value entered is not on the list and event fires. If I click ok it entered the new value in the lookup table. If I cancel I keep getting promt with the not on list error form access. How can I click cancel on adding to lookup tale and move on?
Private Sub Combo178_NotInList(NewData As String, Response As Integer)
   Dim strTmp As String
    DoCmd.setwarning = False

    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new Case Type?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
    
        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO tblSubLookup ( Thetext, TheDropdown) " & _
            "SELECT """ & NewData & """ AS TheText,('Case Type');"
        DBEngine(0)(0).Execute strTmp, dbFailOnError
        
        Else
                Exit Sub
    
        'Notify Access about the new record, so it requeries the combo.
        Response = acDataErrAdded
        
               
    End If

End Sub

Open in new window

0
Comment
Question by:seanlhall
  • 8
  • 7
  • 3
18 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34957556
try this

Private Sub Combo178_NotInList(NewData As String, Response As Integer)
   Dim strTmp As String
    DoCmd.setwarning = False

    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new Case Type?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
   
        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO tblSubLookup ( Thetext, TheDropdown) " & _
            "SELECT """ & NewData & """ AS TheText,('Case Type');"
        DBEngine(0)(0).Execute strTmp, dbFailOnError
       
        Else
 
   
        'Notify Access about the new record, so it requeries the combo.
       ' Response = acDataErrAdded
       
         Response = acDataErrContinue

        Exit Sub        
               
    End If

End Sub
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34957564
or this one

Private Sub Combo178_NotInList(NewData As String, Response As Integer)
   Dim strTmp As String
    DoCmd.setwarning = False

    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new Case Type?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
   
        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO tblSubLookup ( Thetext, TheDropdown) " & _
            "SELECT """ & NewData & """ AS TheText,('Case Type');"
        DBEngine(0)(0).Execute strTmp, dbFailOnError
       
        Else
 
   
        'Notify Access about the new record, so it requeries the combo.
       ' Response = acDataErrAdded

        me.Combo178=""
         Response = acDataErrContinue

        Exit Sub        
               
    End If

End Sub
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34957581
this is not correct
      DoCmd.setwarning = False

it should be  

       DoCmd.setwarnings  False
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34957671
also, if you set this
 DoCmd.setwarnings  False


you must trun that to true after using it

 DoCmd.setwarnings  true

in your codes you really don't need it



Private Sub Combo178_NotInList(NewData As String, Response As Integer)
   Dim strTmp As String


    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new Case Type?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
   
        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO tblSubLookup ( Thetext, TheDropdown) " & _
            "SELECT """ & NewData & """ AS TheText,('Case Type');"
        DBEngine(0)(0).Execute strTmp, dbFailOnError
       
        Else
 
   
        'Notify Access about the new record, so it requeries the combo.
       ' Response = acDataErrAdded

        me.Combo178=""
         Response = acDataErrContinue

        Exit Sub        
               
    End If

End Sub

Open in new window

0
 

Author Comment

by:seanlhall
ID: 34957826
No luck I tried everything.
0
 
LVL 84
ID: 34957884
You need to include a second response OUTSIDE the If block for your MsgBox:

If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then
  <your code here>
   
   Exit Sub        
   
Else
  Response = acDataErrContinue            
End If

Also, you really don't need the "SELECT" in your insert statement. It can be written like this:

strTmp = "INSERT INTO tblSubLookup (Thetext, TheDropdown) VALUES('" & NewData & "', 'Case Type')"



0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34957903
<No luck I tried everything. >

what exactly do you mean?

this is the problem you posted
   <If I cancel I keep getting promt with the not on list error form access. How can I click cancel on adding to lookup tale and move on?>

and the codes i revised prevents the error.
0
 
LVL 84
ID: 34960489
Exactly what do you mean by "Cancel"? Your MsgBox shows Yes and No buttons. Do you mean you get this error when you click "No", or do you get it when you do something else?

Note also that my suggestion is the same as Cap's - i.e. including the acDataErrContinue in the Else section of your IF msgBox block. I just couldn't read it, with the indentations of the code block. Only change I'd make would be to remove the "Exit Sub" from that block, since it's meaningless (and could cause unexpected results). Your logic flow will take you to the End Sub statement eventually, so unless you have a specific reason to use "Exit Sub", it's best to remove it.
0
 

Author Comment

by:seanlhall
ID: 34960872
The error I receive after clicking NO is the following. "The text you entered isn't an item in the list" "Select an item in the list or select an item in the list. I think it is because the the limit to list property is yes. If I select no on this property the not in list event will not fire.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 84
ID: 34961040
If you set a Breakpoint on this line:

Response = acDataErrcontinue

Do you actually get to that line?

You might also try commenting out this line:

me.Combo178=""

or replace it with this:

Me.Combo178.Undo
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34961173
seanlhall,

post the codes that YOU are using..
0
 

Author Comment

by:seanlhall
ID: 34962788
Here is a test file. It will produce the same error. open frmsubject. NotinList.mdb
0
 

Author Comment

by:seanlhall
ID: 34962801
If you want to type in a case type that you dont want to save in the lookup table it is not possible.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34962874
test this and post your comment
NotinList.mdb
0
 

Author Comment

by:seanlhall
ID: 34962997
When I type something that is not on the list, i get the popup to add it or not. If I chose no it clears the box. I want to click no and move on storing the value in the control source case status and not store it in the lookup table.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34963023
then why not just set the limit to list property to NO.
0
 

Author Comment

by:seanlhall
ID: 34963024
I am going to use what you sent. If the user does not like what they have added to the lookup table they can just remove it later. Clearing the combo forces them to select a value from the list or adding on to it with out getting the error. Thanks.
0
 

Author Comment

by:seanlhall
ID: 34963113
If I did that the Not on List Event does no work.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now