Deleting the current entry

csdrex87

Registered User.
Local time
Today, 09:38
Joined
Jul 1, 2009
Messages
66
I'm working on a button that takes the user to the previous entry for that date/employee. I have that coded but the problem is that I need it to delete the record that they had put in for that date.

Example they put in 1/1/09 and enter data... they try to save... an error message pops up saying data for that date already exists would you like to edit... they click yes then it goes to the previous entry for 1/1/09

The problem is it saves the entry for the previous data as well... and i cant do a beforeUPDATE event because they need to be able to edit and that will catch if they are trying to edit somethign already there.
I also cant do an unbound form because my boss claims that its too much code for someone like him to do when i leave.

All i need is to delete the data before it gets saved when i move to that new record. Thanks for your help.... here is where i want it to go:

iEmpId = DCount("Emp_ID", "tblEmployeeDaily", "Emp_ID = " & Me.Emp_ID & " And DailyDate=#" & Me.DailyDate & "#")

If iEmpId <> 0 Then

If (MsgBox("An entry for this date already exists. " & vbCrLf & _
vbCrLf & "Would you like to edit that record?", _
vbOKCancel, "Duplicate Employee") = vbOK) Then
****** Deletion code here *********
Me.Recordset.FindFirst "DatabaseID = " & Me.DatabaseID & " And DailyDate = #" & Me.DailyDate & "#"

End If
 
Try this:

Create a form variable (When the form opens) and set it to "False". If the record exists set it to "True". In the before update event check the variable and cancel the event if it's value is "True". I haven't tested this and it may not work - :)
 
I like the logic in that. So ideally then if the variable is true then it restricts any saves, but if it were false then the user could edit.

How does the outline of the code look to create a new variable? (I can figure the logic out on my own just need the syntax really)
 
In the form code module at top do something like:

Code:
Option Compare Database
Option Explicit

Public MyVarName As String

Then in the form open event set it with something like:

Code:
MyVarName = "False"
 

Users who are viewing this thread

Back
Top Bottom