ConvertToUpperCase




' This code allows you to pass your Forms Controls collection in

' and it will set all textboxes to be upper case.

'


'

' WinAPI Declarations

'

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const ES_UPPERCASE& = &H8&

Public Sub ConvertToUpperCase(ctlCollection As Object)
On Error GoTo vbErrorHandler

Dim lStyle As Long
Dim lRet As Long
Dim cCtl As Control

For Each cCtl In ctlCollection
If TypeOf cCtl Is TextBox Then
lStyle = GetWindowLong(cCtl.hwnd, GWL_STYLE)
lStyle = lStyle Or ES_UPPERCASE
lRet = SetWindowLong(cCtl.hwnd, GWL_STYLE, lStyle)
End If
Next


Exit Sub

vbErrorHandler:
ShowError Err.Number, Err.Description, Err.Source & "::ConvertToUpperCase"

End Sub










( converttouppercase.html )- by Paolo Puglisi - Modifica del 17/12/2023