Solved

Delete Combo Box Item ?

Posted on 1998-11-06
7
281 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

760 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

17 Experts available now in Live!

Get 1:1 Help Now