i am trying to trigger tab key in keypress event of text box

If KeyAscii = 13 Then
SendKeys "{tab}"
End If

but getting error
Run time error 70

permission denied

any help

Inside the if/then you should set

KeyAscii = 0

since you have handled it. however I don't think that will fix your error. have you tried hitting the Tab key and seeing what happens. Have a look at what is next in the tab order after the text box,

I did not get that error when I try it myself.

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
   SendKeys "{tab}"
End If
End Sub

What operating system are you running, XP, Vista or win 7?

Sendkeys will not work in Vista or Win 7, hence my question. There is a work around once I know which OS you are using.:)

win 7 and the code is on user control text box for date field and there are more then one date field on same form so cannot move focus by keypress event since there is no keypress event for user control. i am not using tab to move focus .

The following code works fine in Vista and win7 -

'You have to have ms scripting runtime referenced -
Dim WshShell As Object

Set WshShell = CreateObject("WScript.Shell")

WshShell.SendKeys "{Tab}"
This question has already been answered. Start a new discussion instead.