You've got this all mixed up.
Let's take a capital âAâ for example.
KeyAscii into the KeyPress Sub would be 65.
This is the same as the return value of Asc("A").
Chr(KeyAscii) would return the String âAâ. (Chr() returns strings...)
There is no string for the escape key, so I don't really know what the value of Char is in your routine.
You already have the ASCII value when you enter the Sub. So just use
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then Unload Me
End Sub
I'm not certain that Unload Me will work (a quick experiment would confirm or deny), but I'm sure about the ASCII conversion mixup.