G
Guest
I am trying to design an database that allocates standard tasks to a job. I
have a table called tasks and am using a command button on a form to create
records in this table after the user has entered a job no. Creating the tasks
works ok but I want to stop the tasks from duplicating if anyone presses the
button again. I have tried the following code but it won't work the programme
always seems to find the first record in the table and use this value. If I
substitute the Me.JobNo for an actual value in the table it does work - very
grateful for any suggestions
code currently is
Private Sub btnCreateTasks_Click()
'add records to tasks table
Dim dbJobs As DAO.Database
Dim rsJobs As DAO.Recordset
Dim txtJobNo As String
Dim strFind As String
Set dbJobs = CurrentDb
Set rsJobs = dbJobs.OpenRecordset("tblTasks", dbOpenDynaset)
txtJobNo = Me.JobNo
rsJobs.FindFirst "JobNo = 'Me.JobNo'"
If rsJobs.NoMatch = True Then
rsJobs.AddNew
rsJobs![TaskID] = Nz(DMax("[TaskID]", "tblTasks"), 0) + 1
rsJobs![JobNo] = Me.JobNo
rsJobs![TaskDescrp] = "Order long delivery items"
rsJobs![CompDate] = Me.FitDate - 21
rsJobs.Update
rsJobs.AddNew
rsJobs![TaskID] = Nz(DMax("[TaskID]", "tblTasks"), 0) + 1
rsJobs![JobNo] = Me.JobNo
rsJobs![TaskDescrp] = "Send Painter Schedule"
rsJobs![CompDate] = Me.FitDate - 7
rsJobs.Update
Else
MsgBox "The tasks are already assigned"
End If
End Sub
have a table called tasks and am using a command button on a form to create
records in this table after the user has entered a job no. Creating the tasks
works ok but I want to stop the tasks from duplicating if anyone presses the
button again. I have tried the following code but it won't work the programme
always seems to find the first record in the table and use this value. If I
substitute the Me.JobNo for an actual value in the table it does work - very
grateful for any suggestions
code currently is
Private Sub btnCreateTasks_Click()
'add records to tasks table
Dim dbJobs As DAO.Database
Dim rsJobs As DAO.Recordset
Dim txtJobNo As String
Dim strFind As String
Set dbJobs = CurrentDb
Set rsJobs = dbJobs.OpenRecordset("tblTasks", dbOpenDynaset)
txtJobNo = Me.JobNo
rsJobs.FindFirst "JobNo = 'Me.JobNo'"
If rsJobs.NoMatch = True Then
rsJobs.AddNew
rsJobs![TaskID] = Nz(DMax("[TaskID]", "tblTasks"), 0) + 1
rsJobs![JobNo] = Me.JobNo
rsJobs![TaskDescrp] = "Order long delivery items"
rsJobs![CompDate] = Me.FitDate - 21
rsJobs.Update
rsJobs.AddNew
rsJobs![TaskID] = Nz(DMax("[TaskID]", "tblTasks"), 0) + 1
rsJobs![JobNo] = Me.JobNo
rsJobs![TaskDescrp] = "Send Painter Schedule"
rsJobs![CompDate] = Me.FitDate - 7
rsJobs.Update
Else
MsgBox "The tasks are already assigned"
End If
End Sub