Dim db As DAO.Database
Dim i As Integer
Set db = CurrentDb
db.Execute "Delete * from tblLabels", dbFailOnError
If IsNull(Me!txtNumberOfLabels) Then
MsgBox "Please indicate the number of labels you want to print", vbOKOnly, "Error"
DoCmd.GoToControl "txtNumberOfLabels"
Exit Sub
End If
For i = 1 To Me!txtNumberOfLabels
Const Sql_Insert As String = _
"Insert into tblLabels" & _
"(BoxNr,Crop,Variety,Gen,Line,NetWeight,Customer,PackNo,Dessicated,HarvestedFrom,LabelNo) " & _
"Values(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)"
With Db.CreateQueryDef("", SQL_Insert)
.Parameters(0) = Me.CustomerID
.Parameters(1) = Me.txtCrop
.Parameters(2) = Me.txtVariety
.Parameters(3) = Me.txtGen
.Parameters(4) = Me.txtLine
.Parameters(5) = Me.txtWeight
.Parameters(6) = Me.txtCustomer
.Parameters(7) = Me.Country
.Parameters(8) = Me.txtDessicated
.Parameters(9) = Me.txtHarvestedFrom
.Parameters(10) = Me.Country
.Execute dbFailOnError
.Close
End With
Next i
DoCmd.OpenReport "Customer Label Report", acViewPreview
set db = nothing