473,661 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox DblClick event not firing within class module

3 New Member
I have a form in Access 2007 with many listbox controls on it. I want to run a certain routine that does something with the highlighted value in the listbox whenever any of them are double clicked. But it does not work.

I created a class that is supposed to handle this. Very simplified, and named "clsMyClass ", it looks like this:
Expand|Select|Wrap|Line Numbers
  1. Private WithEvents lstThisBox As Access.ListBox
  2.  
  3. Public Property Set ThisList(ByRef lst As Access.ListBox)
  4.     Set lstThisBox = lst
  5. End Property
  6.  
  7. Private Sub lstThisBox_DblClick(Cancel As Integer)
  8.     Call MyRoutine(lstThisBox)
  9. End Sub
  10.  
To demonstrate the problem, I created a form with a listbox named "List5" to use the class to handle it:
Expand|Select|Wrap|Line Numbers
  1. Private clsListBox As clsMyClass
  2.  
  3. Private Sub Form_Load()
  4.     Set clsListBox = New clsMyClass
  5.     Set clsListBox.ThisList = Me.List5
  6. End Sub
  7.  
This does not work: when I double-click the List5 control, "MyRoutine" does not run. However, it does run if I define the DblClick event in the form -- even without anything in it, i.e.:
Expand|Select|Wrap|Line Numbers
  1. Private Sub List5_DblClick(Cancel As Integer)
  2. End Sub
  3.  
Can anyone explain this? Is there any way around this? Thanks for your help on this ...

--bobkohn
May 20 '10 #1
4 5964
ADezii
8,834 Recognized Expert Expert
@bobkohn
Just subscribing, will look into this matter a little later.
  1. Where does MyRoutine() reside and what is its Scope?
  2. Kindly post the Code for MyRoutine().
May 20 '10 #2
ADezii
8,834 Recognized Expert Expert
Access doesn't bother raising an Event for an Outside Object to Sink unless it thinks that it must. You must make sure that all Events you wish to Trap include the Text "[Event Procedure]" in the associated Property. The code listed below will work. Pay special attention to Code Block #1, Line #7.
  1. 'In the Class Module clsMyClass
    Expand|Select|Wrap|Line Numbers
    1. Private WithEvents lstThisBox As Access.ListBox
    2.  
    3. Public Property Set ThisList(ByRef lst As Access.ListBox)
    4.   Set lstThisBox = lst
    5.  
    6.   'Let's Trap the Double Click Event only
    7.   lst.OnDblClick = "[Event Procedure]"
    8. End Property
    9.  
    10. Private Sub MyRoutine(lst As Access.ListBox)
    11.   MsgBox "ListCount Property of " & lst.Name & " = " & lst.ListCount & _
    12.          vbCrLf & vbCrLf & "Item Selected is: " & lst.ItemData(lst.ListIndex)
    13. End Sub
  2. In Form's Declarations
    Expand|Select|Wrap|Line Numbers
    1. Private clsListBox As clsMyClass
  3. In the Form's Load() Event
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Load()
    2.   Set clsListBox = New clsMyClass
    3.   Set clsListBox.ThisList = Me.List1
    4. End Sub
  4. Any questions, feel free to ask.
May 20 '10 #3
bobkohn
3 New Member
Thank you, ADezii, for figuring this out so quickly. I know where to ask for answers from now on ...

--bobkohn
May 21 '10 #4
ADezii
8,834 Recognized Expert Expert
@bobkohn
You are quite welcome. Be advised that you can also set this Property for all List Boxes either manually or programmaticall y, as in:
Expand|Select|Wrap|Line Numbers
  1. Dim ctl As Control
  2.  
  3. For Each ctl In Me.Controls
  4.   If ctl.ControlType = acListBox Then
  5.     ctl.OnDblClick = "[Event Procedure]"
  6.   End If
  7. Next
May 21 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2342
by: Shane Bishop | last post by:
I've been fighting with the Page_Load event firing twice. I looked through this user group and saw several other people having similar problems. There were various reasons for it: AutoEventWireup="true" instead of AutoEventWireup="false" Spyware software And having your events all wired wrong I had done everything to my machine, stripped it down to just have ..NET on it and I was still having this problem until...
8
1788
by: Paul | last post by:
Hi, In a class i built, i fire an event when a field changes. In a webform that has an instance of the class, the event (from the class) is fired and the code is executed. However, my webpage does not reload (postback) after the event fires. How do i get the webform to postback when the event fires (after the code in the event is done executing)? Thank you, Paul
4
6085
by: Larry Morris | last post by:
The following code, pasted into a web form with a link button on it, will cause the page_unload event to fire twice. If I remove the response.redirect, the problem goes away :). I've got a work around, but I'm curious how one is supposed to programmatically navigate between web pages without the page_unload event firing twice. Thanks, Larry
1
5061
by: RedGST | last post by:
Hello, Im somewhat new to asp.net, so bear with me. I have created a form that has a Listbox along with 2 command buttons & a few other non-important controls. The command button is tied to the OnClick Event. My problem is that when the command button is clicked, the Listbox OnSelectedIndexChanged event gets fired before the command buttons OnClick
2
1692
by: Gman | last post by:
Hi, I have created a usercontrol, a grid control essentially. Within it I have a class: clsGridRecord. I have coded the events such that when a user clicks on the grid, say, the events occur on the parent form. This is fine. The problem occurs when I want to raise an event for a user clicking on one of the clsRecords which are on the grid. So I've placed: Public Event GridRecordClicked(ByVal rec As clsGridRecord,
16
9180
by: tommaso.gastaldi | last post by:
Hello, A probably dumb question... does anyone know hot to avoid that if one keep the mouse pressed on an arrow of the numericUpDown it continues to fire events (it uses evidently a timer) ? I want 1 event for each click, and no timer activation. I have tried using disable within the handler but does not work.
2
8887
by: Paul_Madden via DotNetMonster.com | last post by:
I am handling the Listbox DrawItem event to enable the listbox strings to be displayed in different colours for easy reading. Have set ScrollAlwaysVisible and HorizontalScrollbar to true. I Anchor the listbox T, L, R, B on the parent form The string items held within the listbox are quite big, much longer than could be displayed within the Listbox display area.
1
1272
by: pkiddie | last post by:
Hi! Im having real issues understanding delegates/events in .NET v1, and was hoping someone could shed some light on where I'm not quite understanding. I've got this piece of code in a base user control, which i've called 'PropertyPanel'. In it is the following code: public delegate void EventHandler(object sender, EventArgs e); public event EventHandler AppliedProperties;
1
7049
by: superjacent | last post by:
Hope someone can point me in the right direction. When opening a form the 'click' event of the ListBox is invoked (run). I thought the 'click' event of the ListBox is only invoked when clicking it. I've looked all over the preceeding and other events on the form and definitely do not invoke the ListBox 'Click' event. What does happen during form initialisation or setup (load) is that the rowsource, columnwidths, columncount etc are...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.