Solved

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

Posted on 2002-03-21
19
163 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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