snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Private Sub txtorder_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim lstRw As Long
If KeyCode = 13 Then 'Or KeyCode = 9 Then
'txtWave.Activate
If ValidateForm Then
With Worksheets("Scan Data")
lstRw = .Range("b" & .Rows.Count).End(xlUp).Row + 1
.Range("b" & lstRw).Value = Me.txtWave.Value
.Range("c" & lstRw).Value = Me.txtorder.Value
End With
End If
End If
End Sub
ผมลองเขียน Code มาแล้วครับ แต่พอ Scan ถึงช่อง Part No. Cursor มันไม่เด้งกลับไปที่ช่อง Tag ลูกค้า เพื่อทำการ Scan ต่อครับ
Concept
ทำการ Scan ที่ช่อง Tag ลุกค้า จากนั้นให้ Auto Enter ไปที่ช่อง Part No. จากนั้นให้ Auto บันทึกข้อมูลใน Sheet "Scan Data" และให้ CurSor Auto Enter กับไปที่่ช่อง Tag ลูกค้า วนไปเรือยๆครับ
If Trim(txtWave.Value) = "" Then
MsgBox " Confirm?", vbOKOnly + vbInformation, "Wave"
txtWave.BackColor = vbRed
txtWave.Activate
ValidateForm = False
ElseIf Trim(txtorder.Value) = "" Then
MsgBox " order can't be left blank.", vbOKOnly + vbInformation, "Order"
txtorder.BackColor = vbRed
txtorder.Activate
ValidateForm = False
End If
End Function
Private Sub txtWave_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
txtorder.Activate
End If
End Sub
Function Reset()
Application.ScreenUpdating = False
txtWave.Value = ""
txtWave.BackColor = vbWhite
txtorder.Value = ""
txtorder.BackColor = vbWhite
Application.ScreenUpdating = True
End Function
Private Sub cmdReset_Click()
Dim i As Integer
i = MsgBox("Do you want reset?", vbQuestion + vbYesNo + vbDefaultButton2, "Form Reset")
If i = vbYes Then
Call Reset
End If
End Sub
Private Sub txtorder_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Application.ScreenUpdating = False
Dim iRow As Long
If KeyCode = 13 Then 'Or KeyCode = 9 Then
'txtWave.Activate
iRow = Sheets("Scan Data").Range("A1048576").End(xlUp).Row + 1
End With
Call Reset
Else
If KeyCode = 13 Then 'Or KeyCode = 9 Then
'txtOrder.Activate
End If
Exit Sub
End If
Application.ScreenUpdating = True
End If
End Sub