I have this code that creates several records, if my [OrderNr] is 1111 and my [Aantal] is 5. It will create 5 records with [SerialNumber] like this: 111101, 111102, 111103, 11104, 111105.
I have another textbox named [Start], I want that to be the start number, so let's say I put in [OrderNr] 1111 and in [Aanta] 6 and in [Start] 13, then I want the [SerialNumber] to be: 111113, 111114, 11115, 111116, 11117, 111118. Is this possible?
Private Sub OpenForm_Click()
Dim strToTextBox As String
Dim strAantal As Integer
Dim intHowManyCopies As Integer
strAantal = Me.Aantal
On Error Resume Next
intHowManyCopies = CInt(strAantal)
On Error GoTo 0
If intHowManyCopies <> 0 Then
For intCopy = 1 To intHowManyCopies
If intCopy < 10 Then
strToTextBox = Me.OrderNr & "0" & CStr(intCopy)
Else
strToTextBox = Me.OrderNr & CStr(intCopy)
End If
CurrentDb.Execute "INSERT INTO Geleidelijst " & _
"(SerialNmbr, InvoerOrderNr, InvoerAantal, InvoerSapArtNr, InvoerVermogen, LS1, InvoerSAPItemName, LS2, HS1, HS2) " & _
"VALUES('" & strToTextBox & "','" & Me.OrderNr & "'," & Me.Aantal & ",'" & Me.SapArtNr & "','" & Me.Vermogen & "','" & Me.LS1 & "','" & Me.SAPItemName & "','" & Me.LS2 & "','" & Me.HS1 & "','" & Me.HS2 & "')"
Next intCopy
End If
DoCmd.OpenForm "GeleidelijstForm"
DoCmd.GoToRecord acDataForm, "GeleidelijstForm", acLast
Dim t1 As Long, i As Long
t1 = CLng(Nz(Me.Aantal, 1))
DoCmd.GoToRecord acDataForm, "GeleidelijstForm", acLast
For i = 1 To t1 - 1
DoCmd.GoToRecord acDataForm, "GeleidelijstForm", acPrevious
Next i
DoCmd.Close acForm, "OrderinvoerForm"
Call Forms.GeleidelijstForm.PrintFrm_Click
End Sub
CodePudding user response:
Why not! Do the following changes in your code :
Dim intStart As Integer
intStart = CInt(Me.Start)
And modify your For
loop For intCopy = 1 To intHowManyCopies
to this :
For intCopy = intStart To intStart intHowManyCopies - 1
Here, intStart = 13, so the For
starts with 13 and loops through 18 (13 6-1)