>Yes creating a ActiveX is one way but you can also use a class.
>But I will let Éric Moreau or Guy Barrette expline it, because I do not have a simple example to show online.
>>
>>Since there is no inheritance in VB, what is the best way to reuse this functionality on other form without cut & paste the code in each control KeyPress() event? Do I have to create an ActiveX control?
>>
>>TIA
>>
>>>Another option would be to change the text to uppercase after the user leaves the textbox.
As Jean-René said, you can use a class in which you write standard behaviour that you want your controls to adopt.
This is what you write in the class:
Option Explicit
Public WithEvents gctlTextbox As TextBox
Private Sub gctlTextbox_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub
Then on a form add 2 textboxes and paste these lines:
Option Explicit
Private mctlTextbox As Class1
Private Sub Form_Load()
Set mctlTextbox = New Class1
Set mctlTextbox.gctlTextbox = Text1
End Sub
Then run it. You will see that characters entered in the first textbox will be converted to uppercase (as inhereted (VB doesn't have real inherentance but this is a beginning!!!) from the class). Characters typed in the second textbox aren't converted since we do not mapped this textbox to the class.
Let me know if you need more explanation (and maybe which parts are problematic)!
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com