J
Jess
hI!
The below code traps the keypress event in a class module for two given
textboxes -text1 & text2-.
How can I modify the below code to get the keypress event trapped in this
class module for every textbox on this form? I have a form with 30 textboxes
I would like the CTextBxN class to raise events in my form. Therefore an
array of classes may not acceptable since the class has been declared with
the withevents keyword.
Thanks for your help
'*************************************************************
'this code can trap events in a class module for two textboxes
'form code
'text1 is a textbox on this form
Option Compare Database
Option Explicit
'class declared with withevents keyword since events will be raised in this
form
Dim withevents amount As CTextBxN
Private Sub Form_Close()
End Sub
Private Sub Form_Load()
Set amount = New CTextBxN
Set amount.AddTextBox = Text1
Set amount.AddTextBox = Text2
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
End Sub
'class code
Option Compare Database
Option Explicit
'Event dummy(dummy As String)
Private counter As Integer
Private WithEvents TextBox1 As TextBox
Private WithEvents TextBox2 As TextBox
Public Property Set AddTextBox(avalue As TextBox)
counter = counter + 1
MsgBox (counter)
If counter = 1 Then Set TextBox1 = avalue
If counter = 2 Then Set TextBox2 = avalue
End Property
Private Sub TextBox1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 31
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TextBox2_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 31
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Class_Initialize()
counter = 0
End Sub
The below code traps the keypress event in a class module for two given
textboxes -text1 & text2-.
How can I modify the below code to get the keypress event trapped in this
class module for every textbox on this form? I have a form with 30 textboxes
I would like the CTextBxN class to raise events in my form. Therefore an
array of classes may not acceptable since the class has been declared with
the withevents keyword.
Thanks for your help
'*************************************************************
'this code can trap events in a class module for two textboxes
'form code
'text1 is a textbox on this form
Option Compare Database
Option Explicit
'class declared with withevents keyword since events will be raised in this
form
Dim withevents amount As CTextBxN
Private Sub Form_Close()
End Sub
Private Sub Form_Load()
Set amount = New CTextBxN
Set amount.AddTextBox = Text1
Set amount.AddTextBox = Text2
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
End Sub
'class code
Option Compare Database
Option Explicit
'Event dummy(dummy As String)
Private counter As Integer
Private WithEvents TextBox1 As TextBox
Private WithEvents TextBox2 As TextBox
Public Property Set AddTextBox(avalue As TextBox)
counter = counter + 1
MsgBox (counter)
If counter = 1 Then Set TextBox1 = avalue
If counter = 2 Then Set TextBox2 = avalue
End Property
Private Sub TextBox1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 31
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub TextBox2_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 0 To 31
Case 48 To 57
Case Else
KeyAscii = 0
End Select
End Sub
Private Sub Class_Initialize()
counter = 0
End Sub