Multiple Control Event Classes

From: MartinS (martin_at_idontwantspam.com)
Date: 03/17/05


Date: Thu, 17 Mar 2005 00:54:58 -0800

Hi all
I have set up a form with sixty textbox controls on it to allow the user
to enter some data. After starting to write Enter, KeyPress and
AfterUpdate event procedures for each control, I realised that there
must be an easier way, so did a bit of hunting and found the class event
approach. Deleted all my procedures and set it all up again using the
class approach. Now, the problem I'm having is that I have more than
one event for each control, i.e. AfterUpdate, KeyPress and Enter. The
keypress event seems to fire perfectly, but the Enter and AfterUpdate
events don't. I have set up a different class for each data entry type
(I'm entering dates and numbers) and when populating the control arrays
at form initialisation, I determine what to do with each textbox control
by specific text in it's name.
Are there issues with using multiple class events for the same control?
Is there a way to get this to work?

Regards, and thanks in advance

Martin

This is what I have done (if it's of any use):

Private TBDATES() As New TBDateClass
Private TBNUMS() As New TBNumberClass

Private Sub UserForm_Initialize()
Dim TBD_COUNT As Integer, TBN_COUNT As Integer
Dim CTL As Control
TBD_COUNT = 0
TBN_COUNT = 0
    For Each CTL In Me.Controls
        With CTL
            If TypeName(CTL) = "TextBox" And .Parent.Name = "Frame1"
Then
                If InStr(.Name, "DATE") > 0 Then
                    TBD_COUNT = TBD_COUNT + 1
                        ReDim Preserve TBDATES(1 To TBD_COUNT)
                            Set TBDATES(TBD_COUNT).TBDGroup = CTL
                Else
                    TBN_COUNT = TBN_COUNT + 1
                        ReDim Preserve TBNUMS(1 To TBN_COUNT)
                            Set TBNUMS(TBN_COUNT).TBNGroup = CTL
                End If
            End If
        End With
    Next CTL
End Sub

Then I have set up two class modules:

TBDateClass

code:
Public WithEvents TBDGroup As MSForms.TextBox

Private Sub TBDGroup_AfterUpdate()
With TBDGroup
'...my code
End With
End Sub

Private Sub TBDGroup_Enter()
With TBDGroup
'...my code
End With
End Sub

Private Sub TBDGroup_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'...my code
End Sub

TBNumberClass

code:
Public WithEvents TBNGroup As MSForms.TextBox

Private Sub TBNGroup_AfterUpdate()
With TBNGroup
'...my code
End With
End Sub

Private Sub TBNGroup_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'...my code
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: Open form with Enter key???
    ... code from the KeyPress_Event BUT hade the Locked propertie set for the ... > Every Access control has a KeyPress event. ... > Private Sub txtMyTextBox_KeyPress ...
    (microsoft.public.access.formscoding)
  • RE: Actual Date
    ... control is populated programmatically as it is in this case. ... The only thing wrong with that is that now the calendar ... Private Sub cmdMonthDown_Click ... Select Case KeyCode ...
    (microsoft.public.access.gettingstarted)
  • RE: Filter records based on user input
    ... Private Sub Text2_GotFocus ... I thought that the bookmark line would set the focus to the control in the ... which would filter your form based on the text in the textbox. ... It should filter the records as the user types the number. ...
    (microsoft.public.access.formscoding)
  • Re: how to place the cursor in the field of a subform
    ... Open form and set cursor to PayDate ... the control on the subform on the tab control. ... Doug Steele, Microsoft Access MVP ... Private Sub PayDate_Enter ...
    (microsoft.public.access.formscoding)
  • RE: Drag & Drop in ListBox Ctrl: Find pointer position on mouse up
    ... It is fantastique, I am going now to add the drag and drop bits, and we'll ... This control is much more flexible that the regular Listbox: ... Private Sub Lvw_ItemClick ... Dim THT As LVHITTESTINFO ...
    (microsoft.public.excel.programming)

Quantcast