J
Jess
Hi!
I recently posted a question to find out how to get access to fire a control
event -k eypress event for textbox- in a class module.
The below code, posted by a responder, works. However, I must declare twice
the keypress event, in the form and in the class. If I wished the keypress
event to be fired in a class module for every textbox in a given form, I
would have to declare a keypress event for each textbox in the intended form.
Is there anyway to accomplish this without declaring the event in the form?
Visual Basic 6 can accomplish this by declaring the keypress event once in
the class module. I wonder if VBA lets you do the same.
Thanks
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
'i would like this code to accomplish tjhe same without the
'below keypress event declaration
'I do not wish to declare a keypress event in the form for every textbox
Private Sub Text0_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii & " from form."
End Sub
---
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
---
I recently posted a question to find out how to get access to fire a control
event -k eypress event for textbox- in a class module.
The below code, posted by a responder, works. However, I must declare twice
the keypress event, in the form and in the class. If I wished the keypress
event to be fired in a class module for every textbox in a given form, I
would have to declare a keypress event for each textbox in the intended form.
Is there anyway to accomplish this without declaring the event in the form?
Visual Basic 6 can accomplish this by declaring the keypress event once in
the class module. I wonder if VBA lets you do the same.
Thanks
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
'i would like this code to accomplish tjhe same without the
'below keypress event declaration
'I do not wish to declare a keypress event in the form for every textbox
Private Sub Text0_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii & " from form."
End Sub
---
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
---