Solved

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

Posted on 2002-03-21
19
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses
Course of the Month9 days, 14 hours left to enroll

624 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