Solved

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

Posted on 2002-03-21
19
166 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

856 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