Solved

Key Ascii

Posted on 2002-04-08
4
1,979 Views
Last Modified: 2008-03-10
Hi,

I have a password field where i display the password entered with a * and i append one more * to make it look like ** for every key stroke. I want to disable the space bar key from the password.. The code i have still gives one * for space bar..how do i supress it.


If KeyAscii = 32 Then
MsgBox "Space is not a valid key", vbOKOnly
txtPassword.SetFocus
Exit Sub

Else
txtPassword.Text = txtPassword.Text & "*"
txtPassword.SelStart = Len(txtPassword.Text)
End If

If KeyAscii = 8 Then
txtPassword.Text = Mid(txtPassword.Text, 1, Len(txtPassword.Text) - 2)
txtPassword.SelStart = Len(txtPassword.Text)
End If


Thanks
0
Comment
Question by:sramkris
  • 3
4 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 6927408
If KeyAscii = 32 Then
   MsgBox "Space is not a valid key", vbOKOnly
   txtPassword.SetFocus
    KeyAscii = 0
Exit Sub

0
 
LVL 17

Accepted Solution

by:
inthedark earned 100 total points
ID: 6927420
Also suggest that you set the PasswordChar property of the textbox to "*"

In this way you only need the following code (EXAMPLE FOR TEXT1):

Private Sub Text1_KeyPress(KeyAscii As Integer)

Static ValidKeys As String
Static Done As Boolean

If Not Done Then
    ' ADD YOU VALID KEYS HERE:
    ValidKeys = "0123456789abcdefghijklmnopqrstuvwxyzABCDEGHIJLKMNOPQRSTUVWXYZ`¬!""£$%^&*(){}_+=[]/\?><,.;:'"
End If
If InStr(ValidKeys, Chr(KeyAscii)) = 0 Then
    KeyAscii = 0
    MsgBox "Invalid Password Key", vbExclamation, "Error"
    Text1.SetFocus
End If

End Sub

Hope this helps....inthedark
0
 
LVL 5

Expert Comment

by:KarcOrigin
ID: 6927421
Hi,
Try this -


Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then KeyAscii = 0
End Sub
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6927423
Woops

If Not Done Then
   Done = True ' I forgot this
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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

12 Experts available now in Live!

Get 1:1 Help Now