Solved

Always Accept in Capital in any of the text box or Combo.

Posted on 2002-03-21
19
164 Views
Last Modified: 2010-05-02
I have fully developed system with more than 50 forms in it ,& n number of Text boxes & combo for entry purpose.
Now there is a requirement to accept all the values into Capital, I do not want to create control & replaces every where. Is there a way to make caps lock on as soon as user presses any key on key board.
0
Comment
Question by:tanvirs
  • 6
  • 4
  • 4
  • +3
19 Comments
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6886795
Private Sub Text1_Change()

    Text1.Text = UCase(Text1.Text)

End Sub
0
 
LVL 1

Expert Comment

by:slavikn
ID: 6886839
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii >= Asc("a")) And (KeyAscii <= Asc("z")) Then
        KeyAscii = KeyAscii - 32
    End If
End Sub
0
 
LVL 1

Expert Comment

by:slavikn
ID: 6886842
My example works much faster.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6886856
slavikn: but they'll still be able to cut and paste?
0
 

Author Comment

by:tanvirs
ID: 6886862
Please note i do not want to write code on each control.
As suggest below

Private Sub Text1_Change()

   Text1.Text = UCase(Text1.Text)

End Sub

0
 

Author Comment

by:tanvirs
ID: 6886870
All the suggession are based on writing lot amount of code, For eg. If i have 50 Text boxes i need to write key press on each text boxes which i do not want to do.
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 30 total points
ID: 6886958
how bout this:

basically when form is activate presses capslock (if it's off) and when form is unloaded presses it again (if it's on)

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2

Private Const VK_CAPITAL = &H14


Private Sub Form_Activate()

    '' check if caps is pressed
    If GetKeyState(VK_CAPITAL) <> 1 Then
        '' turn caps on
        keybd_event VK_CAPITAL, 0, 0, 0
        keybd_event VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0
    End If
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
    '' be nice turn caps off
    If GetKeyState(VK_CAPITAL) = 1 Then
        keybd_event VK_CAPITAL, 0, 0, 0
        keybd_event VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0
    End If

End Sub

however, i'd probably turn caps off either in form_Deactivate or lostfocus (i just can't get those events to fire in my test)

0
 
LVL 1

Expert Comment

by:COAtheGREAT
ID: 6886968
Best solution is to create ActiveX control but you dont want to.
0
 
LVL 1

Expert Comment

by:alaplume
ID: 6886989
How about converting all everything to CAPS only immediately before saving to the database. Assuming that your design in reasonable, this should be very easy to implement.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:alaplume
ID: 6886990
How about converting all everything to CAPS only immediately before saving to the database. Assuming that your design in reasonable, this should be very easy to implement.
0
 
LVL 1

Expert Comment

by:alaplume
ID: 6886991
How about converting all everything to CAPS only immediately before saving to the database. Assuming that your design in reasonable, this should be very easy to implement.
0
 
LVL 1

Expert Comment

by:alaplume
ID: 6886993
How about converting all everything to CAPS only immediately before saving to the database. Assuming that your design in reasonable, this should be very easy to implement.
0
 
LVL 1

Expert Comment

by:alaplume
ID: 6886994
How about converting all everything to CAPS only immediately before saving to the database. Assuming that your design in reasonable, this should be very easy to implement.
0
 
LVL 1

Expert Comment

by:alaplume
ID: 6886995
How about converting all everything to CAPS only immediately before saving to the database. Assuming that your design in reasonable, this should be very easy to implement.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6887002
alternatively you can do something like:

Private Sub Form_KeyPress(KeyAscii As Integer)
   If (KeyAscii >= Asc("a")) And (KeyAscii <= Asc("z")) Then
       KeyAscii = KeyAscii - 32
   End If
End Sub

just make sure that the form's keypreview property is set to true.


0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6887006
i do agree w/ alaplume to convert everything before writing to db... b/c in all of the above examples (except for the change event on each textbox) the user will still be able to cut/paste text in
0
 
LVL 1

Expert Comment

by:CodeWizrd
ID: 6887090

Yes, without a change event on every listbox, and without creating (or using an existing) control which masks them for you, you will not be able to catch all conditions.

You will either have to bite the bullet and make massive changes to your app (the easiest way to achieve EXACTLY what you are asking for), or do as alaplume suggests and convert when you write the record.

Good luck, either way.
0
 

Author Comment

by:tanvirs
ID: 6887129
This code will work Fully Now....
===================================



Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2

Private Const VK_CAPITAL = &H14

Private Sub Form_Activate()

   '' check if caps is pressed
   If GetKeyState(VK_CAPITAL) <> 1 Then
       '' turn caps on
       keybd_event VK_CAPITAL, 0, 0, 0
       keybd_event VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0
   End If
   
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim iVal As Integer

  '' check if caps is pressed
   If GetKeyState(VK_CAPITAL) <> 1 Then
       '' turn caps on
       iVal = KeyAscii
       KeyAscii = 0
       keybd_event VK_CAPITAL, 0, 0, 0
       keybd_event VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0
       KeyAscii = iVal - 32
   End If


End Sub

0
 

Author Comment

by:tanvirs
ID: 6887133
set Form property keypreview = True for my example.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now