Bringing list box to front in vba

J

Jose

I have a list box that becomes visible once an image is
clicked on. The list box does become visible only that
since there is another list box below the image, this
list box won't let me see the full list of the new list
box. It seems that the list box that becomes visible on
the click looses focus or something. Is there any way
that in vba i can set focus on a list box?
Thanks
 
J

Jose

I tried focus on the list box in vba and it does have
focus because if i scroll down with the mouse wheel the
records move, but unless i don't scroll wheel options are
hidden by the other list box.
 
S

Stephen Lebans

Here's aprevious post of mine on this subject:

Message 4 in thread
From: Stephen Lebans ([email protected])
Subject: Re: Un-highlight Listbox Selection


View this article only
Newsgroups: comp.databases.ms-access
Date: 2002-02-08 15:49:05 PST


I've run into this problem before. If you force the ListBox to
completely redraw itself then your issue should resolve itself.

' API Declarations for Sub to clear selections
Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd&,
lpRect As RECTL, ByVal bErase&) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd&, lpRect
As RECTL) As Long


Private Type RECTL
left As Long
top As Long
right As Long
bottom As Long
End Type

Private Const API_TRUE As Long = 1&

' This sub is required to eliminate a bug/feature
' in Access with ListBoxes that we programmatically select rows in.
' Access does not redraw the control unless we cover up the entire
' control. We fake this by invalidating the entire window.
' Unless you have cached the hWnd the control must have the focus for
this
' to work.

Public Sub ClearSelections(Optional hWnd As Long)
Dim rc As RECTL

' Were we passed a hWnd?
' If not then get current control's hWnd
If hWnd = 0 Then hWnd = GetFocus

Call GetClientRect(hWnd, rc)
Call InvalidateRect(hWnd, rc, API_TRUE)

End Sub
' Code End



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

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