Code:
Private Sub butAdd_Click()
'Add entry to list
'Insert vs Update options
'If the part is not in the list
If Me.ID.Tag & "" = "" Then
'add the part to the list
'Add main part
CurrentDb.Execute "INSERT INTO BOM(Assembly, Component, Description, AssemblyQty, UOM, CageCode, UnitPriceA, VendorA, UnitPriceB, VendorB, UnitPriceC, VendorC) " & _
" VALUES ('" & Me.txtAssembly & "','" & Me.txtComponent & "','" & Me.txtDescription & "','" & Me.numAssemblyQty & "','" & Me.txtUOM & "','" & _
Me.txtCageCode & "','" & Me.txtUnitPriceA & "','" & Me.txtVendorA & "','" & Me.txtUnitPriceB & "','" & Me.txtVendorB & "','" & Me.txtUnitPriceC & "','" & Me.txtVendorC & "')"
'If there is an AlternateA, Add AlternateA
If Not (Me.txtAlternateA & "" = "" And Me.txtCageCodeA & "" = "") Then
CurrentDb.Execute "INSERT INTO BOM(Component, Description, UOM, CageCode) " & _
" VALUES ('" & Me.txtAlternateA & "','" & Me.txtAltADescription & " \ALT" & "','" & Me.txtAltAUOM & "','" & Me.txtCageCodeA & "')"
End If
'If there is an AlternateB, Add AlternateB
If Not (Me.txtAlternateB & "" = "" And Me.txtCageCodeB & "" = "") Then
CurrentDb.Execute "INSERT INTO BOM(Component, Description, UOM, CageCode) " & _
" VALUES ('" & Me.txtAlternateB & "','" & Me.txtAltBDescription & " \ALT" & "','" & Me.txtAltBUOM & "','" & Me.txtCageCodeB & "')"
End If
'update an already existing part
ElseIf InStr(Me.txtDescription, " \ALT") > 0 Then
CurrentDb.Execute "UPDATE BOM " & _
" SET Component='" & Me.txtComponent & "'" & _
", Description='" & Me.txtDescription & "'" & _
", UOM='" & Me.txtUOM & "'" & _
", Cage Code='" & Me.txtCageCode & "'" & _
" WHERE ID=" & Me.frmEntrySub.Form.ID
Else
CurrentDb.Execute "UPDATE BOM " & _
" SET Assembly='" & Me.txtAssembly & "'" & _
", Component='" & Me.txtComponent & "'" & _
", Description='" & Me.txtDescription & "'" & _
", AssemblyQty='" & Me.numAssemblyQty & "'" & _
", UOM='" & Me.txtUOM & "'" & _
", Cage Code='" & Me.txtCageCode & "'" & _
", UnitPriceA='" & Me.txtUnitPriceA & "'" & _
", VendorA='" & Me.txtVendorA & "'" & _
", UnitPriceB='" & Me.txtUnitPriceB & "'" & _
", VendorB='" & Me.txtVendorB & "'" & _
", UnitPriceC='" & Me.txtUnitPriceC & "'" & _
", VendorC='" & Me.txtVendorC & "'" & _
" WHERE ID=" & Me.frmEntrySub.Form.ID
End If
'Clear form after add/update
butClear_Click
'Refresh form
frmEntrySub.Form.Requery
End Sub
Areas in blue are where I think the error is occurring, but I'm not sure.