Here is the full code, maybe it will help. Note: year is a text field and ccr_no is an integer
Dim email, emailCC, ref, origin, destination, notes, strBody, order, record, part, sn, strSQL As String
Dim rs As Recordset
Dim db As Database
Dim getYear, currYear As String
Dim ccr As Integer
order = Me.work_ord
record = Me.mrf_id
part = Me.part_rec
sn = Me.serial
getYear = Right(CStr(year(Now())), 2)
If warranty = False Then
Exit Sub
Else
'***email recipients***
email = "user@isp.com"
emailCC = "user@isp.com"
ref = "Warranty Repair Review"
'***Set up message body using fields.
strBody = "A new customer service work order " & order & " has been opened. "
strBody = strBody & "Please look at MRF form # " & record & " to review the warranty return. "
strBody = strBody & "Part number Received: " & part
strBody = strBody & " Serial Number: " & sn
'*** send email notificiation
DoCmd.SendObject acSendNoObject, , , email, emailCC, , ref, strBody, True
'***Add new Customer Corrective Action Report
strSQL = "SELECT ccr_no, year FROM WIR"
Set db = CurrentDb()
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
rs.MoveLast
With rs
currYear = .Fields("year")
If currYear = getYear Then
ccr = .Fields("ccr_no") + 1
Else
ccr = 1
End If
End With
createNewCCR:
DoCmd.SetWarnings False
strSQL = "INSERT INTO WIR ( wir_no, corrective_action, customer, part_no, serial_no, compaint, comp_verified, rma ) "
strSQL = strSQL & "SELECT work_ord, sugg_rep, customer, part_rec, serial, discrepancy, verfied, rma FROM MRF WHERE work_ord = " & "'" & Me.work_ord & "'"
DoCmd.RunSQL strSQL
strSQL = "UPDATE WIR SET WIR.ccr_no = " & "'" & ccr & "'" & " WHERE WIR.wir_no = " & "'" & Me.work_ord & "'"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
End If
errorhandler:
Exit Sub
'****end code****
End Sub