password on text box

teiben

Registered User.
Local time
Today, 18:47
Joined
Jun 20, 2002
Messages
462
I'm trying to enable a textbox if the password is entered correctly else no entry. I'm getting a type mismatch error

This is my code, on gotfocus, the textbox "responsibility"
Private Sub Responsibility_GotFocus()
Dim strInput As String, strMsg As String

strMsg = "Enter the password."
strInput = InputBox(Prompt:=strMsg, Title:="Password", XPos:=2000, YPos:=2000)

If strInput = "QUERY" Then

MsgBox "Hello Nancy, "
Responsibility.Enabled = True
Else
MsgBox "that's incorrect"
Responsibility.Enabled = False
NoEntry
End If
End Sub
 
Since you have so few lines of code here you can easily "comment out" lines one by one until you find the culprit. Based on a glance, I would start with the line that says NoEntry.

Code:
Dim strInput As String, strMsg As String 

strMsg = "Enter the password." 
strInput = InputBox(Prompt:=strMsg, Title:="Password", XPos:=2000, YPos:=2000) 

If strInput = "QUERY" Then 

MsgBox "Hello Nancy, " 
Responsibility.Enabled = True 
Else 
MsgBox "that's incorrect" 
Responsibility.Enabled = False 

'Take out the next line and see if the error goes away.
'NoEntry 

End If

Regards,
Tim
 
teiben,

You will run into further issues with this code.

As the "responsibility" text box has focus, you will not be able to set enabled to false. (Or if the text box is enabled = false by default, it will not be able to receive focus, and thus you code will not initiate)

You could however lock the text box using the same logic you have applied above.

Code:
Private Sub Responsibility_GotFocus()
Dim strInput As String, strMsg As String

strMsg = "Enter the password."
strInput = InputBox(Prompt:=strMsg, Title:="Password", XPos:=2000, YPos:=2000)

If strInput = "QUERY" Then

MsgBox "Hello Nancy, "
Responsibility.Locked = False
Else
MsgBox "that's incorrect"
Responsibility.Locked = True
'NoEntry
End If

End Sub

Note that I have commented out the NoEntry line as Tim mentioned.

HTH

Brad.
 
That's IT! I figured there was something else I could use besides enable! Thanks a million
 

Users who are viewing this thread

Back
Top Bottom