Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delete Combo Box Item ?

Posted on 1998-11-06
7
Medium Priority
?
292 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

926 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