Question about a textbox_change event in Excel Userform

FuNeS13

Board Regular
Joined
Oct 25, 2016
Messages
160
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
  3. Web
Hello all,

Am I right to say that after this txtbx_Change event is run the cursor/focus should be set to the same textbox, right?

VBA Code:
Private Sub TextBox1_change()
If Not Len(TextBox1.Value) = 14 Then
        Exit Sub
    Else
End If

Dim SN As String
SN = TextBox1.Value

    Call Label_Print_Code(SN)
   
Application.Wait (Now + TimeValue("0:00:01"))
Me.TextBox1.SetFocus
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
It should be, is that not happening?
 
Upvote 0
It should be, is that not happening?

It does work on my computer, but when I run it on a desktop it doesn't, goes back to a previous combo box.
 
Upvote 0
You can put that code here.

Here you go.

VBA Code:
Public Sub Label_Print_Code(SN As String)
Dim SapGuiAuto 'As Object 
Dim SapApp 'As Object 
Dim SapCon 'As Object 
'Dim Session As Object 


'Connect to SAP input Data"

    Set SapGuiAuto = GetObject("SAPGUI") 
    Set SapApp = SapGuiAuto.GetScriptingEngine
    Set SapCon = SapApp.Children(0) 
    Set session = SapCon.Children(0) 



session.findById("wnd[0]/usr/subSUBSCR_SERIAL_NO:SAPLZEGL_LB51:8010/tblSAPLZEGL_LB51LG_IOTAB_CTR/txtZEGLS_SERIOT-START[2,0]").Text = SN

session.findById("wnd[0]/usr/subSUBSCR_SERIAL_NO:SAPLZEGL_LB51:8010/tblSAPLZEGL_LB51LG_IOTAB_CTR/txtZEGLS_SERIOT-START[2,0]").SetFocus
session.findById("wnd[0]/usr/subSUBSCR_SERIAL_NO:SAPLZEGL_LB51:8010/tblSAPLZEGL_LB51LG_IOTAB_CTR/txtZEGLS_SERIOT-START[2,0]").caretPosition = 14
session.findById("wnd[0]/usr/subSUBSCR_PRINTER:SAPLZEGL_MP11:8010/cmbCCGLC_PRN-NAME").Key = "000000000000000041"

session.findById("wnd[0]/usr/btnDRUCKEN").press




session.findById("wnd[0]/usr/subSUBSCR_SERIAL_NO:SAPLZEGL_LB51:8010/tblSAPLZEGL_LB51LG_IOTAB_CTR/txtZEGLS_SERIOT-START[2,0]").Text = ""
session.findById("wnd[0]/usr/subSUBSCR_SERIAL_NO:SAPLZEGL_LB51:8010/tblSAPLZEGL_LB51LG_IOTAB_CTR/txtZEGLS_SERIOT-START[2,0]").SetFocus
session.findById("wnd[0]/usr/subSUBSCR_SERIAL_NO:SAPLZEGL_LB51:8010/tblSAPLZEGL_LB51LG_IOTAB_CTR/txtZEGLS_SERIOT-START[2,0]").caretPosition = 0


'disconnect from SAP
    Set session = Nothing ' 
    Set SapCon = Nothing ' 
    Set SapApp = Nothing ' 
    Set SapGuiAuto = Nothing '


Me.TextBox1.Value = ""


End Sub
 
Upvote 0
The only weird thing I see is that you are cleaning the textbox1. Let's repeat the setfocus, try this:

VBA Code:
Private Sub TextBox1_change()
  If Not Len(TextBox1.Value) = 14 Then
    Me.TextBox1.SetFocus
    Exit Sub
  End If
  
  Dim SN As String
  SN = TextBox1.Value
  Call Label_Print_Code(SN)
  Application.Wait (Now + TimeValue("0:00:01"))
  Me.TextBox1.SetFocus
End Sub
 
Upvote 0
The only weird thing I see is that you are cleaning the textbox1. Let's repeat the setfocus, try this:

VBA Code:
Private Sub TextBox1_change()
  If Not Len(TextBox1.Value) = 14 Then
    Me.TextBox1.SetFocus
    Exit Sub
  End If
 
  Dim SN As String
  SN = TextBox1.Value
  Call Label_Print_Code(SN)
  Application.Wait (Now + TimeValue("0:00:01"))
  Me.TextBox1.SetFocus
End Sub
The reason why I'm cleaning txtbx1 is because there is going to be a new entry. let me try your code. thanks!
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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