Code:
Private Sub cmdSaveDefect_Click()
Dim oneControl As Object
Dim str As String, InsStr As String
Dim strSingle As String, strDouble As String, strRepSingle As String, strRepDouble As String
Dim RecordSQL As String, cenSQL As String, endSQL As String
Dim iAttachSQL As String
Dim db As Object, rs As Object
Dim i As Integer
Dim strListSource As String
Dim strFileName As String
Dim dteDateTime As Date
Set db = CurrentDb()
strSingle = Chr(39)
strDouble = Chr(34)
strRepSingle = "^^^^"
strRepDouble = "~~~~"
cenSQL = "','"
endSQL = "');"
dteDateTime = Now()
' Check unique indentifier fields
If IsNull(Me.cbxEmployee) Or IsNull(Me.tbxProductUPC) Or IsNull(Me.cbxDefectCat) Or IsNull(Me.cbxDefect) Or IsNull(Me.cbxMarketplace) Or IsNull(Me.tbxCustName) Or IsNull(Me.tbxOrderNum) Or IsNull(Me.cbxStatus) = True Then
MsgBox ("All * fields are required.")
Exit Sub
Else
End If
'Removes quotes and replaces with safe symbols
strCustName = Replace(tbxCustName, strSingle, strRepSingle): strCustName = Replace(strDesc, strDouble, strRepDouble)
strDefectNotes = Replace(tbxDefectNotes, strSingle, strRepSingle): strDefectNotes = Replace(strNotes, strDouble, strRepDouble)
strCallNotes = Replace(tbxCallNotes, strSingle, strRepSingle): strCallNotes = Replace(strImmedAct, strDouble, strRepDouble)
'Inserts record into the table
RecordSQL = ""
RecordSQL = "INSERT INTO DefectEvents (UPC, Category, Employee, Marketplace, Defect, CustomerName, OrderNumber, Status, CallNotes, DefectNotes, CallInit, Date_Time)" _
& "VALUES('" & Me.cbxEmployee.Value & cenSQL & Me.cbxDefectCat.Value & cenSQL & Me.cbxEmployee.Value & cenSQL & Me.cbxMarketplace.Value & cenSQL & Me.cbxDefect.Value & cenSQL & Me.tbxCustName.Value & cenSQL & Me.tbxOrderNum.Value & cenSQL & Me.cbxStatus & cenSQL & Me.tbxCallNotes & cenSQL & Me.tbxDefectNotes & cenSQL & Me.cbxInitiatedBy & cenSQL & dteDateTime & endSQL
CurrentDb.Execute RecordSQL
If Len(Me.lstAttach & vbNullString) = 0 Then
For i = 1 To Me.lstAttach.ListCount
strFileName = "\\ez-wse\company\Engraving\Databases-DO NOT MOVE\DefectAttach\" & Me.tbxOrderNum.Value & "-" & i
strListSource = Me.lstAttach.ListIndex = (i)
iAttachSQL = "INSERT INTO AttachTable (OrderNo, FilePath" & (i) & ")" _
& "VALUES ('" & Me.tbxOrderNum & cenSQL & Me.lstAttach.ListIndex = (i) & endSQL
CurrentDb.Execute iAttachSQL
FileCopy strListSource, strFileName
Next i
Else
End If
'Opens recordset from table for last entry and changes the safe symbols back to quotes
Set rs = db.OpenRecordset("DefectEvents", dbOpenDynaset)
With rs
.MoveLast
.Edit
!CustomerName = Replace(!Employee, strRepSingle, strSingle): !CustomerName = Replace(!CustomerName, strRepDouble, strDouble)
!CallNotes = Replace(!CallNotes, strRepSingle, strSingle): !CallNotes = Replace(!CallNotes, strRepDouble, strDouble)
!DefectNotes = Replace(!DefectNotes, strRepSingle, strSingle): !DefectNotes = Replace(!DefectNotes, strRepDouble, strDouble)
.Update
End With
Set rs = Nothing
Set db = Nothing
'Clears form for more entries or returns to the Home page
If MsgBox("Would you like to enter another record?", vbYesNo) = vbYes Then
For Each oneControl In frmDefectEvent.Controls
Select Case TypeName(oneControl)
Case "TextBox"
oneControl.Value = vbNullString
Case "ComboBox"
oneControl.Index = Null
End Select
Next oneControl
Else
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmHome", acNormal, "", "", , acNormal
End If
End Sub