Public Sub DuplicatesCheck()
End Sub
Public Function DuplicatesCheck() As Boolean
End Function
[COLOR="Blue"] If DuplicatesCheck = False Then
Exit Sub
End If[/COLOR]
'build the SQL Statement
strSQL = "INSERT INTO Resourcing ( Start_Date, Duration, Project_Title, Trainer_Name, Team"
Cancel = True
If intResponse = vbYes Then
DoCmd.OpenForm "Edit Hours", , , strCondition
End If
[COLOR="Blue"] Else
DuplicatesCheck = True[/COLOR]
End If
Change that Sub to a function, like so:
Code:Public [COLOR="Red"]Function DuplicatesCheck() As Boolean[/COLOR] End Function
And did you actually call the module itself DuplicatesCheck? If it's the Module, call it mdlDuplicatesCheck.I've names the module DuplicatesCheck
DuplicatesCheck = True
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intCheck As Integer
Dim strDates As String
Dim strDuration As String
Dim strTrainer As String
Dim strCondition As String
Dim strMessage As String
Dim intResponse As Byte
strTrainer = "[Trainer_Name] = '" & Me.Trainer_Name & "'"
strDates = " AND [Start_Date] IN (#" & Me.Start_Date & "#,#" & Me.End_Date & "#)"
If Me.Duration = "All Day" Then
strDuration = " AND Not [Duration] Is Null"
Else
strDuration = " AND [Duration] IN ('All Day','" & Me.Duration & "')"
End If
strCondition = strTrainer & strDates & strDuration
intCheck = DCount("*", "[Resourcing]", strCondition)
If intCheck > 0 Then
strMessage = "This event clashes with" & IIf(intCheck = 1, " an ", " ") & _
"existing event" & IIf(intCheck > 1, "s", "") & _
vbNewLine & vbNewLine & _
"Do you wish to view and edit the event" & IIf(intCheck > 1, "s?", "?")
intResponse = MsgBox(strMessage, vbYesNo + vbQuestion, "Event clash do you wish to edit the existing event")
If intResponse = vbYes Then
DoCmd.OpenForm "Edit Hours", , , strCondition
End If
Else
DuplicatesCheck = True
End If
End Sub
Private Sub Create_multiple_records_Click()
Dim strSQL As String
If IsNull(Me.Start_Date) Then
MsgBox "Start Date Missing", vbOKOnly + vbCritical, "Error"
Me.Start_Date.SetFocus
ElseIf IsNull(Me.End_Date) Then
MsgBox "End Date Missing", vbOKOnly + vbCritical, "Error"
Me.End_Date.SetFocus
ElseIf IsNull(Me.Cmb_Activity) Then
MsgBox "Activity Missing", vbOKOnly + vbCritical, "Error"
Me.Cmb_Activity.SetFocus
ElseIf IsNull(Me.Cmb_Duration) Then
MsgBox "Duration Missing", vbOKOnly + vbCritical, "Error"
Me.Cmb_Duration.SetFocus
Else
If DuplicatesCheck = False Then
Exit Sub
End If
strSQL = "INSERT INTO Resourcing ( Start_Date, Duration, Project_Title, Trainer_Name, Team"
If Not IsNull(Me.Cmb_Activity) Then
strSQL = strSQL & ", Activity"
End If
strSQL = strSQL & ", Training_Type ) "
strSQL = strSQL & " SELECT Dates.Work_Dates, [Forms]![Resourcing]![Cmb_Duration] AS Expr1, [Forms]![Resourcing]![Cmb_Project_Title] AS Expr2, [Forms]![Resourcing]![Cmb_Trainer_Name] AS Expr3, [Forms]![Resourcing]![Cmb_Team] AS Expr4"
If Not IsNull(Me.Cmb_Activity) Then
strSQL = strSQL & " , [Forms]![Resourcing]![Cmb_Activity] AS Expr5"
End If
strSQL = strSQL & " , [Forms]![Resourcing]![Cmb_Training_Type] AS Expr6 "
strSQL = strSQL & " FROM Dates WHERE (((Dates.Work_Dates)>[Forms]![Resourcing]![Start_Date] And (Dates.Work_Dates)<=[Forms]![Resourcing]![End_Date]))"
DoCmd.RunSQL (strSQL)
End If
Activity = Activity & ": " & [Forms]![Resourcing]![Project_Title]
Me.Requery
DoCmd.GoToRecord , , acNewRec
If CurrentProject.AllForms("2014 Resources").IsLoaded Then
[Forms]![2014 Resources].Requery
If CurrentProject.AllForms("Edit Hours").IsLoaded Then
[Forms]![Edit Hours].Refresh
End If
End If
End Sub
Public Function DuplicatesCheck() As Boolean
Dim intCheck As Integer
Dim strDates As String
Dim strDuration As String
Dim strTrainer As String
Dim strCondition As String
Dim strMessage As String
Dim intResponse As Byte
strTrainer = "[Trainer_Name] = '" & Me.Trainer_Name & "'"
strDates = " AND [Start_Date] IN (#" & Me.Start_Date & "#,#" & Me.End_Date & "#)"
If Me.Duration = "All Day" Then
strDuration = " AND Not [Duration] Is Null"
Else
strDuration = " AND [Duration] IN ('All Day','" & Me.Duration & "')"
End If
strCondition = strTrainer & strDates & strDuration
intCheck = DCount("*", "[Resourcing]", strCondition)
If intCheck > 0 Then
strMessage = "This event clashes with" & IIf(intCheck = 1, " an ", " ") & _
"existing event" & IIf(intCheck > 1, "s", "") & _
vbNewLine & vbNewLine & _
"Do you wish to view and edit the event" & IIf(intCheck > 1, "s?", "?")
intResponse = MsgBox(strMessage, vbYesNo + vbQuestion, "Event clash do you wish to edit the existing event")
If intResponse = vbYes Then
DoCmd.OpenForm "Edit Hours", , , strCondition
End If
Else
DuplicatesCheck = True
End If
End Function