Option Compare Database
Option Explicit
Private Sub btnAddNewRecord_Click()
Dim sSQL As String
Dim nQty As Long
nQty = DLookup("CurrentQty", "tblMaster1", "MasterIDPK=" & MasterIDFK)
Select Case Withdraw
Case True
If nQty - UserQty > 0 Then
sSQL = "UPDATE tblMaster1 Set CurrentQty = CurrentQty - " & [UserQty] & " WHERE MasterIDPK = " & [MasterIDFK]
End If
Case False
sSQL = "UPDATE tblMaster1 Set CurrentQty = CurrentQty + " & [UserQty] & " WHERE MasterIDPK = " & [MasterIDFK]
Case Else
MsgBox "No action taken, 'Withdraw' does not contain a valid entry", vbOKOnly, " I N P U T N E E D E D "
Exit Sub
End Select
If Len(sSQL) > 0 Then
CurrentDb.Execute sSQL, dbFailOnError
Else
MsgBox "No action taken, check your quantities for valid values", vbOKOnly, " C H E C K QTY V A L U E S "
DoCmd.Beep
End If
DoCmd.Close acForm, Me.Name
End Sub