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

RaiseEvent not working

Status
Not open for further replies.

DavePilot

Programmer
Feb 12, 2002
12
0
0
US
I'm working on a good sized project and I am having problems raising an event. So I've just created a little test program to work it out. The code seems to work correctly except I never receive the event in my form??

'------------------
' The CLASS
'------------------
Public Event CustomEvent(strText As String)

Public sub RaiseMyEvent(strText As string)
' Raise the event
RaiseEvent CustomEvent(strText)

End Function

'------------------------
' The FORM
'------------------------
Option Explicit
Dim WithEvents MyEvent As clsEvent
Dim objEvent As New clsEvent

Private Sub Form_Load()
Set MyEvent = New clsEvent
End Sub

Private Sub cmdRaise_Click()
' Load Event Requested
objEvent.RaiseMyEvent(Now)
End Sub

Private Sub MyEvent_CustomEvent(strText As String)
lblEventReceived.Caption = "Event Received: " & strText
End Sub


The event is never received in the Form after the Raise button is clicked.?? Any ideas? I'm stumped.

Thanks,
Dave
 
Two thing you can try.

1. In the class public sub change the 'End Function' to 'End Sub'.

2. You are refering to the wrong instance of your object in the click event. Change

objEvent.RaiseMyEvent(Now)

to

MyEvent.RaiseMyEvent(Now)


That should take care of things.

Thanks and Good Luck!

zemp
 
Thanks. Referring to MyEvent was the trick.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top