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
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,729
Office Version
365
Platform
Windows
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.:)
 

sparky251977

New Member
Joined
Jul 30, 2010
Messages
3
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,729
Office Version
365
Platform
Windows
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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,971
Messages
5,508,470
Members
408,687
Latest member
KevinNTU

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top