S
SodaJim
Hello everyone,
I'm looking for a possible solution for deleting a record(s) via a cmdButton
or another method that will remove a record in a table but will also need to
subtract a value from another table field and replace this with the result...
My end users from time to time will inadvertantly click one of the three
cmdButtons and a later time, need to remove a record as well deduct the value
in hours from another table... Currently, I manually go in and perform this
task but would like to automate this task through permissions available to a
particular group of users...
The code below is currently executed when a cmdButton is clicked. There are
two additional buttons with very similar code that may be clicked. I'm
showing this for reference so you can see the process of record additions.
Thanks for any suggestions or input!
Jim
========================
Private Sub cmdCalled_Click()
Dim myMsg, mySQL As String
Dim otDate As Date
Dim db As DAO.Database
Dim rs As DAO.Recordset
otDate = Forms!frmOvertime![txtOT_Date]
'Double check to see if the OT Hours is Zero
If Forms!frmOvertime![txtOT_Hours] <= 0 Then
myMsg = MsgBox("The Overtime Hours are set to 0" & (Chr(13)) &
"Please enter the number of hours!", vbCritical, "Missing Hours")
Forms!frmOvertime!OT_Hours.SetFocus
Else
myMsg = "Data has been Modified!"
myMsg = myMsg & (Chr(13)) & "Do wish to Save the Changes?"
myMsg = myMsg & (Chr(13)) & "Click YES to Save or No to Discard
Changes."
If MsgBox(myMsg, vbQuestion + vbYesNo, "Save Changes?") =
vbYes Then
'Update Employee Total OT Hours
Forms!frmOvertime!frmEmployees![txtOT_Total_Hours] =
(Forms!frmOvertime!frmEmployees![txtOT_Total_Hours] +
(Forms!frmOvertime![txtOT_Hours] / 2))
'Adding new record in tblEmployeeOvertimes
mySQL = "Insert into tblEmployeeOvertimes (EmployeeID,
OT_CalledDate, OT_NoContact, OT_Hours, OT_Hours_Actual) " & _
"Values ('" & Me.EmployeeID & "', '" & otDate &
"', (-1), '" & Forms!frmOvertime![txtOT_Hours] & "', '" &
(Forms!frmOvertime![txtOT_Hours] / 2) & "')"
DBEngine(0)(0).Execute mySQL, dbFailOnError
'==========================================
DoCmd.Save
Me.Requery
'Code to Disable Command Buttons
cmdCalled.Enabled = False
cmdDenied.Enabled = False
cmdWorked.Enabled = False
Else
DoCmd.RunCommand acCmdUndo
End If
End If
End Sub
=========================
I'm looking for a possible solution for deleting a record(s) via a cmdButton
or another method that will remove a record in a table but will also need to
subtract a value from another table field and replace this with the result...
My end users from time to time will inadvertantly click one of the three
cmdButtons and a later time, need to remove a record as well deduct the value
in hours from another table... Currently, I manually go in and perform this
task but would like to automate this task through permissions available to a
particular group of users...
The code below is currently executed when a cmdButton is clicked. There are
two additional buttons with very similar code that may be clicked. I'm
showing this for reference so you can see the process of record additions.
Thanks for any suggestions or input!
Jim
========================
Private Sub cmdCalled_Click()
Dim myMsg, mySQL As String
Dim otDate As Date
Dim db As DAO.Database
Dim rs As DAO.Recordset
otDate = Forms!frmOvertime![txtOT_Date]
'Double check to see if the OT Hours is Zero
If Forms!frmOvertime![txtOT_Hours] <= 0 Then
myMsg = MsgBox("The Overtime Hours are set to 0" & (Chr(13)) &
"Please enter the number of hours!", vbCritical, "Missing Hours")
Forms!frmOvertime!OT_Hours.SetFocus
Else
myMsg = "Data has been Modified!"
myMsg = myMsg & (Chr(13)) & "Do wish to Save the Changes?"
myMsg = myMsg & (Chr(13)) & "Click YES to Save or No to Discard
Changes."
If MsgBox(myMsg, vbQuestion + vbYesNo, "Save Changes?") =
vbYes Then
'Update Employee Total OT Hours
Forms!frmOvertime!frmEmployees![txtOT_Total_Hours] =
(Forms!frmOvertime!frmEmployees![txtOT_Total_Hours] +
(Forms!frmOvertime![txtOT_Hours] / 2))
'Adding new record in tblEmployeeOvertimes
mySQL = "Insert into tblEmployeeOvertimes (EmployeeID,
OT_CalledDate, OT_NoContact, OT_Hours, OT_Hours_Actual) " & _
"Values ('" & Me.EmployeeID & "', '" & otDate &
"', (-1), '" & Forms!frmOvertime![txtOT_Hours] & "', '" &
(Forms!frmOvertime![txtOT_Hours] / 2) & "')"
DBEngine(0)(0).Execute mySQL, dbFailOnError
'==========================================
DoCmd.Save
Me.Requery
'Code to Disable Command Buttons
cmdCalled.Enabled = False
cmdDenied.Enabled = False
cmdWorked.Enabled = False
Else
DoCmd.RunCommand acCmdUndo
End If
End If
End Sub
=========================