Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Consolidation

Status
Not open for further replies.

bajo71

Programmer
Aug 6, 2007
135
US
Hello,
The following routines take place for the KeyPress and LostFocus event. These routines must be replicated for 28 text boxes. Apart from the name of the textbox, all else remains identical. Is there some way I can call a function in the event rather than pasting the code 28 times?

Private Sub Text10_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is = 119
Exit Sub
Case Is > 69
MsgBox ("You Can Only Enter Letters B,C,D,E,U or W")
End Select
End Sub
Private Sub Text10_LostFocus()
If BadKey = True Then
Text10.Text = ""
ElseIf Len(Me.Text10.Text) > 1 Then
MsgBox ("ONLY B,C,D,E,U and W ARE VALID")
Text10.Text = ""
End If

BadKey = False
End Sub

many thanks............
 



Code:
sub Press()
Select Case KeyAscii
    Case Is = 119
    Exit Sub
    Case Is > 69
    MsgBox ("You Can Only Enter Letters B,C,D,E,U or W")
    End Select
end sub
sub Lost()
If BadKey = True Then
       Text10.Text = ""
    ElseIf Len(Me.Text10.Text) > 1 Then
      MsgBox ("ONLY B,C,D,E,U and W ARE VALID")
      Text10.Text = ""
    End If
    
    BadKey = False
end sub
Private Sub Text10_KeyPress(KeyAscii As Integer)
   Press
End Sub
Private Sub Text10_LostFocus()
   Lost
End Sub


Skip,
[sub]
[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue][/sub]
 
Only problem is the 'Text10' will be different everytime. There will be Text11, Text12 etc. Could I pass a portion of the textbox name ie the number part, as a parameter to the called routine?
 
Which sort of form (UserForm, AccessForm, ...) ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top