mike60smart
Registered User.
- Local time
- Today, 21:37
- Joined
- Aug 6, 2017
- Messages
- 1,995
Hi Everyone
I am trying to use the Code from this Site
When I create the OnClick Event the code shows lines 80 & 130 highlighted in Red ?
Can anyone see where it is wrong?
Any help appreciated
I am trying to use the Code from this Site
When I create the OnClick Event the code shows lines 80 & 130 highlighted in Red ?
Can anyone see where it is wrong?
Any help appreciated
Code:
Private Sub cmdPrint_Click()
10 On Error GoTo cmdPrint_Click_Error
'Print multiple labels for current record.
Dim i As Integer
Dim rst As ADODB.Recordset
20 Set rst = New ADODB.Recordset
'Delete previous label data.
30 DoCmd.SetWarnings False
40 DoCmd.RunSQL "DELETE FROM [tblLabels]"
50 DoCmd.SetWarnings True
60 On Error GoTo errHandler
'Catch blank control.
'If set to 0, label report is blank but runs.
70 If IsNull(Me!txtNumberOfLabels) Then
80 MsgBox "Please indicate the number of labels you want to print", _
90 vbOKOnly , "Error"
100 DoCmd.GoToControl "txtNumberOfLabels"
110 Exit Sub
120 End If
130 rst.Open "[Temporary Customers]", CurrentProject.Connection, adOpenDynamic, _ adLockPessimistic
'Adds duplicate records for selected company using input value.
140 For i = 1 To Me!txtNumberOfLabels.Value
150 With rst
160 .AddNew
'!BoxNr = Me.CustomerID
170 !CROP = Me.txtCrop
180 !Variety = Me.txtVariety
190 !Gen = Me.txtGen
200 !Line = Me.txtLine
210 !NetWeight = Me.txtWeight
220 !Customer = Me.txtCustomer
'!PackNo = Me.Country
230 !Dessicated = Me.txtDessicated
240 !HarvestedFrom = Me.txtHarvestedFrom
'!LabelNo = Me.Country
250 .Update
260 End With
270 Next i
'Opens report.
280 DoCmd.OpenReport "Customer Label Report", acViewPreview
290 rst.Close
300 Set rst = Nothing
310 Exit Sub
'Error handling routine.
errHandler:
320 MsgBox Err.Number & ": " & Err.Description, vbOKOnly, "Error"
330 DoCmd.SetWarnings True
340 rst.Close
350 Set rst = Nothing
360 On Error GoTo 0
370 Exit Sub
cmdPrint_Click_Error:
380 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdPrint_Click, line " & Erl & "."
End Sub