很不推荐你用这种方法,因为很烦,你要判断所的的键,如果要用的话参考以下,其中你错的原因你应该能够看出来了
Option Explicit
Private password As String
Private Sub Command1_Click()
If password = "a" Then
'Unload Form1
'form2.Show
Debug.Print "ok"
End If
If password <> "a" Then
 MsgBox "您的输入有误", 5, "警告"
End If
password = ""
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
Dim char As String
Select Case KeyAscii  Case 48 To 57, 65 To 90, 97 To 122
    char = Chr(KeyAscii)
    password = password + char
    KeyAscii = Asc("*")
  Case Else
    If KeyAscii > 13 And KeyAscii < 127 Then
      KeyAscii = 0
    End If
      
End SelectEnd Sub
这个程序中可以满足你的要求,但很不完善。如果你是普通加密的话,只要把text的password属性设置成true。就可以了。