PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.

Textbox event fired in class module

 
 
Jess
Guest
Posts: n/a
 
      13th Apr 2009
How can I get a given control event -let say the textbox keypress event- to
be fired in a class module? I believe this is called multicasting in VB6.

The below code is the one I am unsuccessfully using: the TextBox_KeyPress is
not fired in the class module.

Form:

Dim amount As CTextBxN

Private Sub Form_Load()

Set amount = New CTextBxN

‘text1 is a textbox control on this form
Set amount.TextBox = Text1

End Sub

CTextBxN Class:


Public WithEvents TextBox as TextBox


public Sub TextBox_KeyPress(KeyAscii As Integer)

….event code…

End Sub

I have noticed that if the form has a declaration for the keypress event,
the latter is fired first in the form, and then in the class module.

In other words. I the below snippet of code is added to the form, the
keypress event is fired first in the form, and second in the class module.

public Sub TextBox_KeyPress(KeyAscii As Integer)


End Sub

Can anybody help me with this?

Thanks in advance

 
Reply With Quote
 
 
 
 
Stefan Hoffmann
Guest
Posts: n/a
 
      13th Apr 2009
hi Jess,
Jess wrote:
> How can I get a given control event -let say the textbox keypress event- to
> be fired in a class module? I believe this is called multicasting in VB6.

Start with this:

The forms code:
---
Option Compare Database
Option Explicit

Private m_TextBox As clsTextBox

Private Sub Form_Close()

Set m_TextBox = Nothing

End Sub

Private Sub Form_Load()

Set m_TextBox = New clsTextBox
Set m_TextBox.TextBox = Text0

End Sub

Private Sub Text0_KeyPress(KeyAscii As Integer)

MsgBox KeyAscii & " from form."

End Sub
---

The class' (clsTextBox) code:
---
Option Compare Database
Option Explicit

Private WithEvents m_TextBox As Access.TextBox

Public Property Set TextBox(AValue As Access.TextBox)

Set m_TextBox = AValue

End Property

Private Sub m_TextBox_KeyPress(KeyAscii As Integer)

MsgBox KeyAscii & " from class."

End Sub
---


mfG
--> stefan <--
 
Reply With Quote
 
 
 
 
Jess
Guest
Posts: n/a
 
      13th Apr 2009
Stephan,

Thanks for your answer. I have a question:

Is there a way to accomplish this without declaring the keypress event in
the form?

I would like the keypress event to be trapped in the class module for every
textbox. Do I have to declare the keypress event for every textbox in the
form?

Thanks

"Stefan Hoffmann" wrote:

> hi Jess,
> Jess wrote:
> > How can I get a given control event -let say the textbox keypress event- to
> > be fired in a class module? I believe this is called multicasting in VB6.

> Start with this:
>
> The forms code:
> ---
> Option Compare Database
> Option Explicit
>
> Private m_TextBox As clsTextBox
>
> Private Sub Form_Close()
>
> Set m_TextBox = Nothing
>
> End Sub
>
> Private Sub Form_Load()
>
> Set m_TextBox = New clsTextBox
> Set m_TextBox.TextBox = Text0
>
> End Sub
>
> Private Sub Text0_KeyPress(KeyAscii As Integer)
>
> MsgBox KeyAscii & " from form."
>
> End Sub
> ---
>
> The class' (clsTextBox) code:
> ---
> Option Compare Database
> Option Explicit
>
> Private WithEvents m_TextBox As Access.TextBox
>
> Public Property Set TextBox(AValue As Access.TextBox)
>
> Set m_TextBox = AValue
>
> End Property
>
> Private Sub m_TextBox_KeyPress(KeyAscii As Integer)
>
> MsgBox KeyAscii & " from class."
>
> End Sub
> ---
>
>
> mfG
> --> stefan <--
>

 
Reply With Quote
 
Stefan Hoffmann
Guest
Posts: n/a
 
      14th Apr 2009
hi Jess,

Jess wrote:
> I would like the keypress event to be trapped in the class module for every
> textbox. Do I have to declare the keypress event for every textbox in the
> form?

Ah, okay. I didn't understand it the first time. Afaik you need this
modification (in my example):

clsTextBox:
---
Public Property Set TextBox(ATextBox As Access.TextBox)

Set m_TextBox = ATextBox

If m_TextBox.OnKeyPress = "" Then
m_TextBox.OnKeyPress = "[Event Procedure]"
End If

End Property
---

Caveat: If a matching event procedure exists in the code behind the
form, then it is called also.


mfG
--> stefan <--
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event fired in class module (revisisted) Jess Microsoft Access VBA Modules 0 14th Apr 2009 01:59 PM
Difference between Form's Class Module and Class Module tobesurveyor via AccessMonster.com Microsoft Access VBA Modules 4 14th Apr 2006 01:08 PM
Class in a module or class in a class? cj Microsoft VB .NET 4 3rd Mar 2006 11:29 PM
Imagebutton event fired when enter key pressed in a single line textbox dave@palfery.com Microsoft Dot NET Framework 0 28th Apr 2005 08:13 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge Microsoft ASP .NET 2 26th May 2004 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:48 AM.