Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need VB to loop until I click Close Form button

Status
Not open for further replies.

DamnTheMachine

Technical User
Dec 29, 2004
3
CZ
Hi,
Heres the code I have for scanning into Excel (5 barcodes of each box). What I cant figue out is how to et program to make automatic carriage return after scanning 5th barcode (for the others Im moving using autotab )and loop this util I click Close Form button
Thanks a lot !!
------------------
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row

'check for a Advice Note number
If Trim(Me.txtAdvice.Value) = "" Then
Me.txtAdvice.SetFocus
MsgBox "Please scan Advice Note number"
Exit Sub
End If

'check for a Part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please scan Part Number"
Exit Sub
End If

'check for a Quantity
If Trim(Me.txtQty.Value) = "" Then
Me.txtQty.SetFocus
MsgBox "Please scan Quantity"
Exit Sub
End If

'check for a Supplier Number
If Trim(Me.txtSupplier.Value) = "" Then
Me.txtSupplier.SetFocus
MsgBox "Please scan Supplier Number"
Exit Sub
End If

'check for a Serial number
If Trim(Me.txtSerial.Value) = "" Then
Me.txtSerial.SetFocus
MsgBox "Please scan Serial Number"
Exit Sub
End If


'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtAdvice.Value
ws.Cells(iRow, 2).Value = Me.txtPart.Value
ws.Cells(iRow, 3).Value = Me.txtQty.Value
ws.Cells(iRow, 4).Value = Me.txtSupplier.Value
ws.Cells(iRow, 5).Value = Me.txtSerial.Value


'clear the data
Me.txtAdvice.Value = ""
Me.txtPart.Value = ""
Me.txtQty.Value = ""
Me.txtSupplier.Value = ""
Me.txtSerial.Value = ""
Me.txtAdvice.SetFocus
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub Image1_Click()

End Sub

Private Sub Label1_Click()

End Sub



Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
 
If you replace:
Code:
Me.txtSerial.Value = ""
Me.txtAdvice.SetFocus
End Sub

with
Code:
Me.txtSerial.Value = ""
cmdAdd = True
End Sub

you fire the cmdadd Click event

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
So my nick shouldnt be DamnTheMachine but DumbA**...:0)) Thanks a lot !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top