I am trying to add an event to a text box that if you press the enter key, it would run the code for the OK button. The following code has been tried.
Private Sub YourControl_KeyPress(KeyAscii As Integer)
If KeyCode = vbKeyEnter Then
Call cmdOk_Click
End If
End Sub
At first, KeyCode generated a Compile Error, that the variable was not define. I changed it to KeyAscii, then the code stopped at vbKeyEnter and got an error as well. I changed that to vbKeyReturn and I get no errors, but nothing happens either.
Any thoughts?
Private Sub YourControl_KeyPress(KeyAscii As Integer)
If KeyCode = vbKeyEnter Then
Call cmdOk_Click
End If
End Sub
At first, KeyCode generated a Compile Error, that the variable was not define. I changed it to KeyAscii, then the code stopped at vbKeyEnter and got an error as well. I changed that to vbKeyReturn and I get no errors, but nothing happens either.
Any thoughts?