Results 1 to 6 of 6
  1. #1
    pdanes is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Posts
    208

    RaiseEvent not working


    I have a class module in which I want to raise an event to signal to the outside world. The class is named clsNode, and all this code is in that class module.

    The declaration section contains this:
    Code:
    Public Event cstmEvntDropPoint(cnode As clsNode) ' If transfer is activated, this will signal the drop point
    and code in the class's MouseDown event routine contains this:
    Code:
    RaiseEvent cstmEvntDropPoint(Me)
    However, the RaiseEvent command does nothing. It activates just fine with other parameters, but even when I define a variable named SelfRef and use Set SelfRef = Me in the class's Initialize routine, subsequently calling
    Code:
    RaiseEvent cstmEvntDropPoint(SelfRef)
    also does nothing. Stepping through the line in the debugger treats that line like a NoOp, but with any other parameter, it works normally. Why does this command accept other things, but not a reference to the current instance of the class raising the event?

  2. #2
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Quote Originally Posted by pdanes View Post
    and code in the class's MouseDown event routine contains this:
    Has the clsNode an event named MouseDown?
    If that event belongs to a member of clsNode, you have to set the member's OnMouseDown property to "[Event Procedure]" in member's Property Set procedure. For example:
    Code:
    Option Compare Database
    Option Explicit
    
    Public Event MouseDown(cNode As clsNode)
    
    Private WithEvents cmdNode As CommandButton
    
    Property Set Node(value As CommandButton)
        Set cmdNode = value
        cmdNode.OnMouseDown = "[Event procedure]"
    End Property
    
    Property Get Node() As CommandButton
        Set Node = cmdNode
    End Property
    
    Private Sub cmdNode_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        RaiseEvent MouseDown(Me)
    End Sub
    Maybe you have to provide more info (code) about your class and its usage.
    How do you declare the instances of the clsNode and how do you listen the events of clsNode from the outside world?

  3. #3
    pdanes is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Posts
    208
    I started to write an explanation, but now realize I have some stuff in it that's not clear even to me. I will have to go through it a bit more carefully, and post back when I have it a bit clearer in my own head.

  4. #4
    pdanes is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Posts
    208
    My apologies - got it. I was being an idiot, as usual.

  5. #5
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Check the following Link and some reference as well on the Article to get the idea as how to set up the WithEvents, RaiseEvent etc. and capture the Event when Raised:

    https://www.msaccesstips.com/2019/04/withevents-and-defining-your-own-events.html

  6. #6
    pdanes is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Posts
    208
    Thank you, that looks very useful. I'm getting better at using custom events, but it's still a bit new to me. Every bit of information helps.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-27-2020, 09:49 AM
  2. Replies: 2
    Last Post: 05-14-2017, 10:07 AM
  3. Working query stops working after importing
    By Abacus1234 in forum Import/Export Data
    Replies: 3
    Last Post: 10-25-2015, 09:12 PM
  4. Replies: 1
    Last Post: 12-27-2014, 12:38 PM
  5. Replies: 3
    Last Post: 01-29-2013, 04:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums