Hi all,
I am trying to update and insert records with SQL statements. Below my code:
Select Case FirstGRV
Case "Y"
sql = "UPDATE Tbl_SellingPrices " & _
"SET SellingPrice = " & Me!Text2 & ", SellingPriceDateFrom = date(), SellingPriceDateTo = #" & Me!Text3 & "#" & _
"WHERE SellingPriceStockCode = Forms!Frm_GRV!GRVStockCode and SellingPriceDateFrom =#01-01-1900#;"
DoCmd.RunSQL sql
Case "N"
Dim db As Database
Set db = CurrentDb
sql = "UPDATE Tbl_SellingPrices " & _
"SET SellingPrice = " & Me!Text2 & " " & _
"WHERE SellingPriceStockCode = Forms!Frm_GRV!GRVStockCode and SellingPriceDateTo = #" & Me!Text3 & "#;"
db.Execute sql
If db.RecordsAffected = 0 Then
sql = "INSERT INTO Tbl_SellingPrices " _
& "(SellingPriceStockCode, SellingPrice, SellingPriceDateFrom, SellingPriceDateTo) VALUES " _
& "(Forms!Frm_GRV!GRVStockCode, " & Me!Text2 & ", date(), #" & Me!Text3 & "#);"
db.Execute sql
End If
End Select
My problem is I need to know if the execution of the SQL statement was successful or not. I use the RecordsAffected method, but it always returns 0, no matter what.
I have now been struggling with this for a week and no closer to a solution.
Can somebody shed light on what I may be doing wrong?
Thanks
Deon
I am trying to update and insert records with SQL statements. Below my code:
Select Case FirstGRV
Case "Y"
sql = "UPDATE Tbl_SellingPrices " & _
"SET SellingPrice = " & Me!Text2 & ", SellingPriceDateFrom = date(), SellingPriceDateTo = #" & Me!Text3 & "#" & _
"WHERE SellingPriceStockCode = Forms!Frm_GRV!GRVStockCode and SellingPriceDateFrom =#01-01-1900#;"
DoCmd.RunSQL sql
Case "N"
Dim db As Database
Set db = CurrentDb
sql = "UPDATE Tbl_SellingPrices " & _
"SET SellingPrice = " & Me!Text2 & " " & _
"WHERE SellingPriceStockCode = Forms!Frm_GRV!GRVStockCode and SellingPriceDateTo = #" & Me!Text3 & "#;"
db.Execute sql
If db.RecordsAffected = 0 Then
sql = "INSERT INTO Tbl_SellingPrices " _
& "(SellingPriceStockCode, SellingPrice, SellingPriceDateFrom, SellingPriceDateTo) VALUES " _
& "(Forms!Frm_GRV!GRVStockCode, " & Me!Text2 & ", date(), #" & Me!Text3 & "#);"
db.Execute sql
End If
End Select
My problem is I need to know if the execution of the SQL statement was successful or not. I use the RecordsAffected method, but it always returns 0, no matter what.
I have now been struggling with this for a week and no closer to a solution.
Can somebody shed light on what I may be doing wrong?
Thanks
Deon