NeverTooLate
New member
- Local time
- Tomorrow, 07:25
- Joined
- Nov 11, 2009
- Messages
- 6
I've written code to update pricing. If some but not all of [UnitPriceNew] fields = 0 then code works. Problem is, if all of the [UnitPriceNew] fields = 0 then the first msgbox is ignored and pricing is updated, which is what I want to avoid at all costs. Please help!
Code:
Private Sub cmdUpdatePrices_Click()
'PURPOSE: In TblParts, update Unit Prices to new prices [UnitPriceNew], delete any Price Rises
'and then delete the New Unit prices.
Dim db As dao.Database
Dim RS As Recordset
Dim strSql As String
Dim intAnswer As Integer
strSql = "SELECT * From TblParts"
Set db = CurrentDb()
Set RS = db.OpenRecordset(strSql, dbOpenDynaset)
'Check if any of the parts don't have a new price
RS.FindFirst RS!UnitPriceNew = 0
'If one or more parts don't have a new price, then ask if user would like to exit this routine
'and open TblParts ready for inputting missing prices.
If not RS.NoMatch Then
intAnswer = MsgBox("One or more parts are missing New Unit Prices. " _
& "Do you want to exit this routine so you can fix the prices? " _
& vbCrLf & vbCrLf & "(No means that the prices will continue to be updated which may result in $0 amounts.)", vbCritical + vbYesNo, "Missing Prices")
Select Case intAnswer
Case vbYes
GoTo Exit_cmdUpdatePrices_Click
Case vbNo 'if No is chosen from the message box, continue to update new prices
End Select
End If
'If no records have UnitPriceNew=0 (or if 'no' was chosen from the msgbox) then continue with this code
RS.MoveFirst
Do Until RS.EOF()
RS.Edit
RS![UnitPrice] = RS![UnitPriceNew]
RS![pricerise] = 0
RS!UnitPriceNew = 0
RS.Update
RS.MoveNext
Loop
MsgBox "Updates to prices are complete"
Exit_cmdUpdatePrices_Click:
DoCmd.OpenTable ("tblParts")
Exit Sub
End Sub
Last edited: