Avoiding delete confirmation pop-up

red7

Registered User.
Local time
Today, 20:19
Joined
Feb 17, 2005
Messages
15
Hi,

I have the code to ensure that if a purchase is made whereby the amount required exceeds the number in stock, then an error message appears to tell the user. The following code presents the error message and also deletes the purchase that the user has just attempted:

Code:
Private Sub TotalPrice_Exit(Cancel As Integer)
'calculate the TotalPrice
    TotalPrice = QuantityPurchased * Forms![frmStock].Price
    
    If Forms![frmStock].QuantityRemaining > Forms![frmPurchase].QuantityPurchased Then
'subtract this amount from QuantityRemaining on frmStock
    Forms![frmStock].QuantityRemaining = Forms![frmStock].QuantityRemaining - QuantityPurchased
    
    Else
    Dim LResponse As Integer

    LResponse = MsgBox("Cannot Purchase - Insufficient Stock Levels", vbExclamation)
    
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    End If
    
End Sub

Is there anyway to avoid the 'you are about to delete one record...' pop-up box that accompanies the delete?

Help much appreciated, my workmates are rather fussy I'm afraid! :D

red.
 
Code:
DoCmd.SetWarnings False
    ' run query here
DoCmd.SetWarnings True


Also,

oCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

That code has been out of date since the release of Access 97 in 1997 - it is the method used in Access 95. I don't know what it's doing (might be saving a record) but it can be replaced using the RunCommand method

i.e.

Code:
DoCmd.RunCommand acCmdSaveRecord
 
Great, thanks for your help SJ :)
 
If you used the Before Update event in conjunction with Me.Undo you wouldn't have to delete anything
 

Users who are viewing this thread

Back
Top Bottom