Solved

Key Ascii

Posted on 2002-04-08
4
1,995 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

790 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