Private Sub cmdBuildSchedule_Click()
Dim datThis As Date
Dim lngActID As Long
Dim lngLocID As Long
Dim lngrojectID As Long
Dim lngOrganizationID As Long
Dim varNotes As Variant
Dim strSQL As String
Dim db As DAO.Database
Dim intDOW As Integer 'day of week
Dim intDIM As Integer 'Day in month
If Me.grpRepeats = 2 Then
If Not CheckDates() Then
Exit Sub
End If
End If
'If Not CheckTimes() Then
' Exit Sub
'End If
If IsNull(Me.cboActID) Then
MsgBox "You must select an Activity.", vbOKOnly + vbInformation, "Enter Activity"
Me.cboActID.SetFocus
Me.cboActID.Dropdown
Exit Sub
End If
If IsNull(Me.cboLocID) Then
MsgBox "You must select a Location.", vbOKOnly + vbInformation, "Enter Location"
Me.cboLocID.SetFocus
Me.cboLocID.Dropdown
Exit Sub
End If
If IsNull(Me.cboOrgID) Then
MsgBox "You must select an organization.", vbOKOnly + vbInformation, "Enter Location"
Me.cboOrgID.SetFocus
Me.cboOrgID.Dropdown
Exit Sub
End If
If IsNull(Me.cboProjectID) Then
MsgBox "You must select a project.", vbOKOnly + vbInformation, "Enter Location"
Me.cboProjectID.SetFocus
Me.cboProjectID.Dropdown
Exit Sub
End If
'strTitle = Me.txtTitle
varNotes = Me.txtNotes
lngLocID = Me.cboLocID
lngrojectID = cboProjectID
lngOrganizationID = Me.cboOrgID
lngActID = Me.cboActID
Set db = CurrentDb
If Me.grpRepeats = 2 Then 'need to loop through dates
For datThis = Me.txtStartDate To Me.txtEndDate
intDIM = GetDIM(datThis)
intDOW = Weekday(datThis)
If Me("chkDay" & intDIM & intDOW) = True Or _
Me("chkDay0" & intDOW) = True Then
strSQL = "INSERT INTO tblTempSchedDates (" & _
"tscDate, OrgID, tscActID, tscLocID, ProjectID, " & _
"tscNotes ) " & _
"Values(#" & datThis & "#," & lngOrganizationID & "," & lngrojectID & "," & lngActID & ", " & _
lngLocID & ", " & _
IIf(IsNull(varNotes), "Null", """" & varNotes & """") & ")"
db.Execute strSQL, dbFailOnError
End If
Next
Else 'dates are there, just add the title, notes, times, location, Activity
strSQL = "Update tblTempSchedDates Set tscActID = " & lngActID & _
", tscLocID = " & lngLocID & ", OrgID = " & lngOrganizationID & ", ProjectID = " & lngrojectID
If Len(varNotes & "") > 0 Then
strSQL = strSQL & ", tscNotes = " & IIf(IsNull(varNotes), Null, """" & varNotes & """")
End If
db.Execute strSQL, dbFailOnError
End If
Me.sfrmTempScheduleEdit.Requery
MsgBox "Temporary schedule built. " & _
"You can now edit the schedule and " & _
"append to the permanent schedule.", vbOKOnly + vbInformation, "Temp schedule complete"
End Sub
|