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.