code help - onkey

B

bforster1

I have put the following code in the module of my main userform;

Sub OnKey
Application.Onkey, "{Tab}", "Update"
End Sub

Sub Update()
TextBox586.Value = Worksheets("IncStmtSummary").Range("F5")
TextBox586.Text = Format(TextBox586.Text, "$#,##0")
End Sub

I am attempting to have TextBox586 update whenever the Tab key i
pressed. It does not work. Any suggestions. Does it matter where
put the code??

Thanks
 
R

Ron de Bruin

Hi

This will work
Don't use Onkey for a macro name because Excel think it is code
In your other code you have a typo ( , after Application.OnKey )

Sub OnKeySub2()
Application.OnKey "{Tab}", "Update"
End Sub

Sub Update()
MsgBox ""
End Sub
 
T

Tim

try this:

Private Sub UserForm_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = vbKeyTab Then
Call Update
End If
End Sub

This code must go in the codebehind the form; Update must be a Public
routine to work.

HTH

Tim
 
R

Ron de Bruin

Oops

You say userform
See Tim his reply

--
Regards Ron de Bruin
http://www.rondebruin.nl


Ron de Bruin said:
Hi

This will work
Don't use Onkey for a macro name because Excel think it is code
In your other code you have a typo ( , after Application.OnKey )

Sub OnKeySub2()
Application.OnKey "{Tab}", "Update"
End Sub

Sub Update()
MsgBox ""
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top