Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


996


strSQL = _
“UPDATE Products SET “ _
& “ProductName = ‘“ & m_ProductName & “‘“ _
& “SupplierID = “ & m_SupplierID _
& “CategoryID = “ & m_CategoryID _
& “QuantityPerUnit = ‘“ _
& m_QuantityPerUnit & “‘“ _
& “UnitPrice = “ & m_UnitPrice _
& “UnitsInStock = “ & m_UnitsInStock _
& “UnitsOnOrder = “ & m_UnitsOnOrder _
& “ReorderLevel = “ & m_ReorderLevel _
& “Discontinued = “ & m_Discontinued _
& “WHERE ProductID = “ & m_ProductID
Else
‘Insert new record:
strSQL = _
“INSERT INTO Products (“ _
& “ProductName,” _
& “SupplierID, “ _
& “CategoryID,” _
& “QuantityPerUnit, “ _
& “UnitPrice,” _
& “UnitsInStock, “ _
& “UnitsOnOrder,” _
& “ReorderLevel, “ _
& “Discontinued “ _
& “)VALUES(“ _
& m_ProductName & “, “ _
& m_SupplierID & “, “ _
& m_CategoryID & “, “ _
& m_QuantityPerUnit & “, “ _
& m_UnitPrice & “, “ _
& m_UnitsInStock & “, “ _
& m_UnitsOnOrder & “, “ _
& m_ReorderLevel & “, “ _
& m_Discontinued & “)”
End If
db.Execute strSQL
SaveProduct = True
ExitHere:
Exit Function
HandleError:
SaveProduct = False
Resume ExitHere
End Function

The code in the SaveProduct method is straightforward. If the m_ProductID variable is larger
than zero, the record in the Products table matching the ProductID is updated. Otherwise, a
new record is inserted into the Products table.
Free download pdf