Solved

Delete Combo Box Item ?

Posted on 1998-11-06
7
282 Views
Last Modified: 2010-04-30
I'm writing a simple Customer DB program using DAO in unbound mode. In the Customer ID fields, combo box is used to list all ID for searching.
My question is:
When I just type in the Customer ID(NOT selecting from mouse) inside the combo, and goto delete this record, I can't delete this item using RemoveItem method. As the ListIndex return -1.
Any ideas? Thanks.
0
Comment
Question by:HenryChanE
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:csalves
ID: 1443467
first you have to search in your list box for listIndex corresponding to your costumer ID. After that you Use the remove item refering the list index returned by your search.

regards,
0
 
LVL 1

Author Comment

by:HenryChanE
ID: 1443468
csalves,
  You response really very fast !!!
  I know want you mean, but how to peform searching inside combo box? Search one by one by moving index is not possible because it is too slow. BTW, an API answer is prefered.

Thanks.

Henry
0
 
LVL 2

Accepted Solution

by:
peterwest earned 50 total points
ID: 1443469
Hi,

You need to use the SendMessage API call - start by putting the following in the general declarations section of a module:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Const CB_FINDSTRINGEXACT = &H158


You can then find the listindex that matches the string you want by using a command like this:

    'Declare variables
    Dim sTextEntered As String
    Dim lRetVal As Long
   
    'Get the string they have typed into the combo
    sTextEntered = Combo1.Text
   
    'Search for it in the appropriate combo
    lIndexFound = SendMessage(Combo1.hWnd, CB_FINDSTRING, 0, sTextEntered)

The value zero that is specified in the SendMessage command denotes what listindex the search should start from.  If an error occurs with the API call then -1 will be returned.

Hope this helps,

Pete
     
0
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.

 
LVL 1

Author Comment

by:HenryChanE
ID: 1443470
peterwest,
  Your approach seems correct, but the code doesn't work. Is there anything wrong? All variables in the API declaration are in Long, but you've put a string(sTextEntered) inside.

Regards,

Henry.
0
 
LVL 2

Expert Comment

by:peterwest
ID: 1443471
Apologies,

I made a few mistakes whilst typing up the code and didn't test it very well - here's the changes.

1) Remove the function declaration for SendMessage and use this instead:

Public Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)

2) Change 'Dim lRetVal As Long' to 'Dim lIndexFound As Long'

3) Change the 'lIndexFound =' line to read:

    lIndexFound = SendMessageByString(Combo1.hwnd, CB_FINDSTRINGEXACT, -1, sTextEntered)

Should work fine now - sorry bout that.

Pete

0
 
LVL 1

Author Comment

by:HenryChanE
ID: 1443472
Thanks.
0
 
LVL 1

Author Comment

by:HenryChanE
ID: 1443473
Thanks.
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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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