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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double click in unbound listbox seems to trigger AfterUpdate event

Status
Not open for further replies.

MickelR

Technical User
Mar 10, 2010
21
NL
I have an unbound listbox that I populate using an SQL statement: Me.lstIssues.RowSource = strSQL. The SQL statement works fine.

The listbox is bound to column 1 which is an unique ID. When I click on an existing row in the listbox, an AfterUpdate event is triggered, which populates a second unbound listbox using another SQL statement that shows more details surrounding the item that I clicked on.

My idea is that clicking once in the unbound listbox triggers the AfterUpdate event, which shows the details in the second unbound listbox. However, double clicking in the unbound listbox should trigger the OnDblClick event, which I would want to use to open a form in which the record can be edited.

The problem is that double clicking the selected record triggers the AfterUpdate event. If I delete the AfterUpdate event from the unbound listbox and then try to double click on a record the form actually does open.

I reckon that the AfterUpdate event is triggered before the OnDblClick event, because the contents of the unbound listbox changes (after all a new record is selected). It looks like that the AfterUpdate event (populating the second unbound listbox with an SQL statement) takes too long for the programm to handle the OnDblClick event.

Does anyone have suggestions to improve the situation and make a "single click" (or actually selecting a record) trigger the AfterUpdate event and a "double click" opening a form to edit the record that has been double clicked on?

Thanks for looking into this!
 
My guess is you'll have to settle for placing a command button beside the Listbox to open yur form.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
That would also be my first suggestion, but here are some other (untested) ideas.

Put a doevents in your afterupdate code. That may allow the double click to catch.

I would try this as well. If the afterupdate returns the same value then you want to open the form.

public oldValue as yourDatatype

private yourList_afterupdate
your code
if yourList = oldValue then
open form
end if
oldvalue = yourlist.value
 
So you understand when you doubleclick the following happens

Enter
gotfocus
mousedown
mouseup
beforeupdate
afterupdate
click
dblclick
mouseup

So from your title, of course the afterupdate happens when you doubleclick. This is why you can not code it to do one thing when you "click" and something different when you "double click". Because the click always happens when you doubleclick
 
Thank you everyone for your input. The way I solved this problem is by creating an invisible field on my form and using the following code:

Private Sub lstIssues_AfterUpdate()

If Me.lstIssues.Value = Me.txtOldIssueValue Then
DoCmd.OpenForm "frmIssues", acNormal
Else
Me.txtOldIssueValue = Me.lstIssues.Value
setCommentSQL 'This is a called function
End If

End Sub

I find it crappy coding, but it works and that's what matters. I believe the solution is similar to what MajP suggested.

Thanks again... I am not sure if and how to close topics, but this one can be closed as far as I am concerned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top