Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KeyUp Event never executes 2

Status
Not open for further replies.

InsaneProgrammer

Programmer
Jan 17, 2001
44
US
I use the code below to make sure the user has entered a UserName and Password before enabling the OK button. I have used this exact code in other applications and it works fine. In the current application I'm developing this code never executes. The Form_KeyUp event never gets called. Anyone have an idea what might cause this? Is it possible that I need to add a reference or something?

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If txtUserName.Text = "" Or txtPassword.Text = "" Then
cmdOK.Enabled = False
Else
cmdOK.Enabled = True
End If
End Sub
 
Make sure the KeyPreview Property of the form is set to True.
RKA:)
 
You might be better putting it on the KeyPress event. As far as I can remember not all keys (function keys etc) dont fire the keyDown and KeyUp events.

Dan.
 
Insane,
Why not use the textbox change event? You could use something like this:
Code:
Private Sub txtUserName_Change()
If txtUserName <> &quot;&quot; And txtPassword <> &quot;&quot; Then
   cmdOK.Enabled = True
Else
   cmdOK.Enabled = False
End If
End Sub

Private Sub txtPassword_Change()
If txtUserName <> &quot;&quot; And txtPassword <> &quot;&quot; Then
   cmdOK.Enabled = True
Else
   cmdOK.Enabled = False
End If
End Sub
A little more code, but it works.
--tbuch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top