Retrieving a control's handle

P

Pranav02

Hi,

I have small piece of code where in I'm trying to use the

Public Declare Function SendMessage Lib "user32"

function. This function requires a control's handle. I have a listbox. I'm
using
Listbox1.[_GethWnd] to retrieve the handle of the control and later use it
in the program as

SendMessage hndl, LB_SELECTSTRING, -1, Textbox1.Text

Ideally, the above code should show the items in the list box starting with
the characters entered in the Textbox. It is not showing so. The code runs
without any errors, however the listbox items do not move/change etc.

Can you please help me in this, all that I want to achieve is auto find an
entry in a listbox using API function in the Word VBA.

Thanks in advance.
 
J

Jonathan West

Pranav02 said:
Hi,

I have small piece of code where in I'm trying to use the

Public Declare Function SendMessage Lib "user32"

function. This function requires a control's handle. I have a listbox. I'm
using
Listbox1.[_GethWnd] to retrieve the handle of the control and later use it
in the program as

SendMessage hndl, LB_SELECTSTRING, -1, Textbox1.Text

Ideally, the above code should show the items in the list box starting
with
the characters entered in the Textbox. It is not showing so. The code runs
without any errors, however the listbox items do not move/change etc.

Can you please help me in this, all that I want to achieve is auto find an
entry in a listbox using API function in the Word VBA.

Unlike the controls in VB6 Forms, VBA controls in UserForms are windowless
and therefore don't have a window handle. You cannot do this trick in VBA.

However, you can achieve much the same effect by assigning a string to the
Text property of the listbox. If the string matches an item in the listbox,
it will be selected and the list will scroll down to display that item. If
the string does not match an item in the listbox, an error is raised which
you can trap.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top