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

x
?
Solved

Delete Combo Box Item ?

Posted on 1998-11-06
7
Medium Priority
?
290 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
[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
  • 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
Technology Partners: 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!

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

670 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