Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem NotinList in Combo box

Posted on 2009-03-30
12
Medium Priority
?
364 Views
Last Modified: 2013-12-05
Hi All,
I am trying to implement NotInList to add new item in Combo box. This is working for add new item without quotation sign. I need to add item with quotation sign for new Item but its giving problem that value are in not in list item.

The quotation sign i am using for Inch. I can't used any substitute for quotation sign.

I am using the code from microsoft site
http://support.microsoft.com/kb/197526

I am using SQL Server 2005 and Access 2003 Access Data Project.

e.g, Item 1 1x1"


Private Sub CustomerID_NotInList (NewData As String, Response As _
                                        Integer)
Dim Result
Dim Msg As String
Dim CR As String
 
    CR = Chr$(13)
 
    ' Exit this subroutine if the combo box was cleared.
    If NewData = "" Then Exit Sub
 
    ' Ask the user if he or she wishes to add the new customer.
    Msg = "'" & NewData & "' is not in the list." & CR & CR
    Msg = Msg & "Do you want to add it?"
    If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
       ' If the user chose Yes, start the Customers form in data entry
       ' mode as a dialog form, passing the new company name in
       ' NewData to the OpenForm method's OpenArgs argument. The
       ' OpenArgs argument is used in Customer form's Form_Load event
       ' procedure.
       DoCmd.OpenForm "Customers", , , , acAdd, acDialog, NewData
    End If
 
    ' Look for the customer the user created in the Customers form.
    Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]='" & NewData & "'")
    If IsNull(Result) Then
       ' If the customer was not created, set the Response argument
       ' to suppress an error message and undo changes.
       Response = acDataErrContinue
       ' Display a customized message.
       MsgBox "Please try again!"
    Else
       ' If the customer was created, set the Response argument to
       ' indicate that new data is being added.
       Response = acDataErrAdded
    End If
End Sub

Open in new window

0
Comment
Question by:Ved Prakash Agrawal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24018082
change this

    Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]='" & NewData & "'")

to

    Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]=" & chr(34) & NewData & chr(34))
0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018158
capricorn1,
Its not working.
I modified the code
  Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]='" & NewData & chr(34) & "'")

AND
  Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]='" & replace(NewData,"""","") & chr(34) & "'")


But the code still not working.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24018211
ved17nov,

compare what you have to what i posted..
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018217
capricorn,
I attached the code where i am testing.

in main form -->Products--> change supplier combo box text to  Testing1"

Thanks
Sample.zip
0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018238
When i tried to use the same code as it is which you suggest. I am getting following error.

Error Message:
Closing delimiter not found for the string beginning at position 79 in the command. The string begins with: "Testing7"")} AS.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24018502
your file can't be opened..

are using { ' } and { " } in your entries?

this should do it

  Result = DLookup("[CompanyName]", "Customers", _
             "[CompanyName]='" & Replace(NewData,"'","''") & "'")



exploded view

                      "[CompanyName]=' " & Replace(NewData," ' "," ' ' ") & " ' ")





0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018615
I am using {"}
0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018656
I am not using double quotation.

shift+'
0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018693
I removed the extension from file. Please add the extension as below.

NorthwindCS.SQL
NorthwindCS_Backup.adp


Sample-adp.zip
0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24018699
Sorry, I am using double quotation.
0
 
LVL 11

Author Comment

by:Ved Prakash Agrawal
ID: 24036784
Hello capricorn1,
did you get tme to look the problem?


Thanks
0
 
LVL 11

Accepted Solution

by:
Ved Prakash Agrawal earned 0 total points
ID: 24191744
I solved myself this problem.

I think the problem is only in adp project and code was working fine with mdb.

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

721 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