Solved

Delete Combo Box Item ?

Posted on 1998-11-06
7
283 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library 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…
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…

777 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