473,802 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class with custom event as subform wrapper

Hello,

I am trying to figure out how to use a class with a custom event as a
wrapper for a subform so that I can automatically trigger things to
happen on the parent form when the custom event is raised. I am new to
custom events, so please bear with me...

I have created a class module (clsMyEvent) as follows:

Option Compare Database
Option Explicit

Private WithEvents mcmd As CommandButton
Public Event MyEvent()

Public Property Set ActionButton(cm d As CommandButton)

Set mcmd = cmd

End Property

Private Sub mcmd_Click()

RaiseEvent MyEvent

End Sub

I then created a form with a single command button on it (cmdRaise) and
set its HasModule property to False. I then created a second form and
embedded the first form in it as a subform and named the subform
'fsub'. Then I added the following code to the second form:

Option Explicit

Dim WithEvents mMyEvent As clsMyEvent

Private Sub Form_Load()

Set mMyEvent = New clsMyEvent
Set mMyEvent.Action Button = Me.fsub.Form.Co ntrols("cmdRais e")

End Sub

Private Sub mMyEvent_MyEven t()

MsgBox "My event!"

End Sub

In this simple example, the intent is to be able to click the command
button on the subform thus triggering display of a messagebox from the
parent form by raising the MyEvent event. However, nothing happens
when I click the command button. It all compiles fine and I get no
errors, but I also get no message box. What am I doing wrong? Any
help greatly appreciated...t hanks!

Bruce

Nov 13 '05 #1
3 4695
rkc
br***@aristotle .net wrote:
Hello,

I am trying to figure out how to use a class with a custom event as a
wrapper for a subform so that I can automatically trigger things to
happen on the parent form when the custom event is raised. I am new to
custom events, so please bear with me...

I have created a class module (clsMyEvent) as follows:

Option Compare Database
Option Explicit

Private WithEvents mcmd As CommandButton
Public Event MyEvent()

Public Property Set ActionButton(cm d As CommandButton)

Set mcmd = cmd

End Property

Private Sub mcmd_Click()

RaiseEvent MyEvent

End Sub

I then created a form with a single command button on it (cmdRaise) and
set its HasModule property to False. I then created a second form and
embedded the first form in it as a subform and named the subform
'fsub'. Then I added the following code to the second form:


Setting the HasModule property of the subform to false is why the event
isn't firing. Change that and your code should work.
Nov 13 '05 #2
rkc
br***@aristotle .net wrote:
One edition to your class.
You have to set the mcmd.OnClick event to an Event Procedure.
So:
1) Set the HasModule property of your fSub form to True
2) Add mcmd.OnClick = "[Event Procedure]"
to the ActionButton property set procedure.
Public Property Set ActionButton(cm d As CommandButton)

Set mcmd = cmd mcmd.OnClick = "[Event Procedure]"

End Property

Nov 13 '05 #3
Thank you RKC...I knew it must be something simple I was overlooking!

Bruce

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4786
by: Steve Amey | last post by:
Hi all I am creating a basic control to perform some tasks, and I want to declare some events to be raised so they can be handled from the form that the control is on. I can create my own Event Handler class and use that, but I would like to use the System.EventArgs class so that my event can be handled by different controls. For example:
6
2440
by: Christian H | last post by:
Hi! I've created a custom control (myDrawControl) that deals with drawing. This control is then added to a form( myMainForm) Now, whenever something is dragged and dropped onto myDrawControl , I want to update a variable in myMainForm that keeps track of the objects that have been added.(ArrayList objectsAdded) Now I'm a little confused... How can I do this, when the method that deals
5
2144
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to run the class it gives an error that "System.Xml.XmlNode.XmlNode() is inaccessible due to its protection level". This error comes because XmlNode has not any public constructor. I found XmlNode has two constructor but both are private or friend...
19
4922
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the exception of custom Collection Classes. Background: I'm developing an A2K .mdb to be deployed as an .mde at my current job-site. It has several custom controls which utilize custom classes to wrap built-in controls, and add additional functionality....
9
1322
by: Lloyd Dupont | last post by:
I have an object which is just a thin wrapper over an other object and might be created in big quantities. something like that: // ===== pseudo-code cample ======= class TheObject { int data; TheWrapper Data { get { return new TheWrapper(data); } }
3
1849
by: Phill W. | last post by:
OK, I've asked nicely before; now I'm going to throw down the gauntlet to anyone brave enough to take it up. In VB'2005, can anyone write me a class that inherits from System.Data.DataTable, add it to a System.Data.DataSet (a /normal/ one, /not/ a subclass), serialise the whole lot to, say, a file and then deserialise the whole shooting match back into the classes they started with? (All my attempts seem to lose all the Type information...
4
2279
by: x taol | last post by:
'class module Public WithEvents clsTxt As TextBox Private Sub clsTxt_Enter() clsTxt.BackColor = VBA.ColorConstants.vbCyan End Sub 'form module Dim txt(1) As New Class1 Private Sub Form_Load() Set txt(0).clsTxt = Me.Text0
2
19496
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9699
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
9562
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
10538
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
10305
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...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6838
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.