Problem with Command Button and textbox.setfocus

chrisgoode

New Member
Joined
Jan 15, 2015
Messages
1
I have a simple excel spread sheet that I am using VBA to run a form. What I want to do is when the enter key is hit on the NextRecord button (which puts the entries into my spreadsheet) I want the focus to turn back to TextBox4. Instead the cursor is moving to the next command box. I know the reason for this is because I have code where I am substituting the tab key for the enter key but I can't figure out another way. This is going to be installed on a handheld with windows mobile so there is no capability for a mouse click. This is my first go at any programming so I greatly appreciate any help. Code snippets that I am using:
  1. Private Sub TextBox4_KeyDown(ByVal KeyCode As _MSForms.ReturnInteger, ByVal Shift As Integer)
  2. If KeyCode = 13 Then KeyCode = 9
  3. End Sub
  4. Private Sub NextRecord_Enter() Dim i As Integer
  5. TextBox4.Text = ""
  6. TextBox4.SetFocus
  7. End Sub
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top