Here??™s how the SaveProduct method would handle the various values of the
m_ProductID variable:
Public Function SaveProduct() As Boolean
Dim db As DAO.Database
Dim strSQL As String
On Error GoTo HandleError
Set db = CurrentDb()
If m_ProductID > 0 Then
???Update existing record:
1063
Object-Oriented Programming with VBA 32
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
SaveProduct = True
ExitHere:
Exit Function
HandleError:
SaveProduct = False
Resume ExitHere
End Function
1064
Professional Database Development Part IV
The code in the SaveProduct method is straightforward.
Pages:
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000