TextBox1 SetFocus Problem

sparky251977

New Member
Joined
Jul 30, 2010
Messages
3
Hi all i have this code, i need it to do what it does which is open a user form with a text box, set the focus on the text box, print when a user clicks the button and then set the focus back to the textbox for another entry.
The problem.. after it performs the print it does not set the focus back to the text box, code as follows...

Private Sub CommandButton1_Click()
ActiveSheet.Cells(31, 4).Value = Str$(Now)
ActiveSheet.Cells(31, 3).Value = TextBox1
Rows("30:30").Select
Selection.Insert Shift:=xlDown
ActiveSheet.Cells(2, 12).Value = TextBox1
ActiveSheet.PageSetup.PrintArea = "$J$5:$N$19"
ActiveSheet.PrintOut Copies:=1, Collate:=True
FileNum = FreeFile
Open "S:\Downloads\EDI&Prod'n\AssyTracking\WIPLog.txt" For Append As #FileNum
Print #FileNum, TextBox1 & "," & Str$(Now)
Close #FileNum
TextBox1 = ""
End Sub

Private Sub UserForm_Initialize()
With TextBox1
.SetFocus
End With
End Sub

Any suggestions greatly appreciated!

Thanks
Andy
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Andy

Do you really need to use SetFocus for the first part?

Just make sure the textbox is the first control in the Tab Order, then it will automatically have focus when the form is opened.

You don't actually seem to have code to set focus back to the text box after the command button has been clicked.:)
 
Upvote 0
I have tried all manner of code to set it back but it doesnt work.
The problem seems to be that after the button is pressed the focus is on the spreadsheet and not the pop up window and hence why the set focus does not work on the text box in the window.
Any ideas would be greatly appreciated.
 
Upvote 0
Andy

I don't see anything in the command button for setting the focus to any control.

What did you try?

This could be somthing to do with printing taking the focus away from the userform, I'll need to check that if I can get my printer to work.

One thought might be to show the form modally.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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