Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When match is found in combox the combox should open without clicking 2

Status
Not open for further replies.

WillemdeNie

Programmer
Sep 15, 2003
44
NL
I have created a combobox to find matching records. After typing some characters the field shows a matching record, but to see all the info (the orther colums and possible other matching records) I have to click on the arrow on the combobox. I would like to have the combo box opened as soon a match is found. How to do??
 
Place this in a module
[tt]
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Public Const CB_SHOWDROPDOWN = &H14F
[/tt]
And, where you want the combo to drop down
[tt]
Call SendMessage(cboClass.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)
[/tt]
Where cboClass is the name of your Combo Box.
 
Thanks for responding! Can you explain a litle how this works? I am not that experienced.
So some declarations (what is "user32")
What does &H14F do?

"Where you want the combo drop down"
That is when I start typing of when a match is found; Is that an event?
 
With this code we are accessing the Windows API (Applications Programming Interface). There are several hundred API calls available in windows. Many of them are available to you as standard parts of the programming language that you are using (e.g. VB, VBS, VBA) but others are not part of those programming languages as directly invokable functions. For example, when you Click on the arrow on a Combo Box, the code behind the combo box object is sending a message to the combo box (which is a control defined by windows) telling it to open. In the normal course of events (i.e. using only your programming language) there is no way for you to cause a combo box to drop down other than by clicking the arrow.

By including a direct reference a the Windows API function in your code (which you do using a DECLARE statement) you can reference it to do things that are not normally part of the programming language.

With that preamble out of the way ...

This DECLARE says that the function SENDMESSAGE is to be found in a Dynamic Link Library named "User32.dll" (again, part of windows.)

Depending on the type of message being sent, there are many possible messages that SENDMESSAGE can transmit and the meaning of a message is specific to the object receiving the message. In this instance, a combo box responds to a message with the HEX value "14F" by dropping the combo list. Other controls may have a different response (or none at all) to the same message.

Find a match...
I don't know how you are determining that a match has been found so its a bit difficult to say exactly where the code should be inserted. You do say that "... the field shows a matching record ..." and I would expect that there is some point in your code at which that match is detected. That's probably where you want to drop the combo.

Just as an aside, a characteristic of a combo box is that, when the list is dropped, the combo receives focus. You can't work on other controls (e.g. type something in a text box) with the combo list dropped. If you try, the combo list will be automatically closed as soon as you remove focus from the combo.

Sorry for being so wordy but APIs are an art form onto themselves and this discussion only scratches the surface.
 
I have putted the code in a module:
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Public Const CB_SHOWDROPDOWN = &H14F
Gives no compilimg errors

Added to the event of the combo box:

Private Sub Combo148_Enter()
Call SendMessage(Combo148.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)
End Sub

Gives a compile error on .hwnd (method not found)
Can you help me once more? I appreciate it very much!

Willem
 
I'm not sure I understand what you need (or Goloms reply, for that sake, API's are out of my league;-)) - If you cant make it work, perhaps look at a workaround, because I don't think the standard access combobox has an event for when the Auto Expand finds a correlating entry, it would need some programming.

One could perhaps use the on change event of the combo, which fires for each typed letter, then compare the .text property of the combo (which would include what's displayed in the combo (whole text if match or just the typed letters if no match)) against the rowsource of the combo, and use the result to issue a dropdown, if match (I think both Golom's code or issuing a .dropdown on the combo would go in there).

But, try out the following, in the combos got focus event, just issue a dropdown:

[tt]Me!Combo148.Dropdown[/tt]

Whenever the combo get's focus, the dropdown will be issued, showing either the previously selected item for this record, or an "unselected" dropdown on new records. Or tell the user that hitting ALT+DownArrow on the keyboard might be recommended when the combo has focus;-)

This doesn't exactly match your description, but would this workaround suffice?

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top