Private Sub cmdLstBoxToOutlook_Click()
Dim db
As DAO.Database
Dim rst
As DAO.Recordset
Dim strSQL
As String
Dim strWhere
As String
Dim intCount
As Integer
Dim i
As Integer
Dim olApp
As Object
Dim olAppt
As Object
If isAppThere("Outlook.Application") =
False Then
Set olApp = CreateObject("Outlook.Application")
Else
Set olApp = GetObject(, "Outlook.Application")
End If
strSQL = "SELECT tblAppointments.* FROM tblAppointments "
strWhere = "WHERE tblAppointments.ApptmntID IN("
For i = 0
To Me.lstAppointments.ListCount - 1
If lstAppointments.Selected(i)
Then
strWhere = strWhere & lstAppointments.Column(0, i) & ", "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
strSQL = strSQL & strWhere
Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
Do Until rst.EOF
Set olAppt = olApp.CreateItem(1)
With olAppt
.Start = Nz(rst!ApptDate) & " " & Nz(rst!ApptTime, vbNullString)
.End = Nz(rst!EndDate) & " " & Nz(rst!EndTime, vbNullString)
.Duration = Nz(rst!ApptLength, 0)
.Subject = Nz(rst!Appt)
.Body = Nz(rst!ApptNotes)
.Location = Nz(rst!Location)
If rst!ApptReminder =
True Then
If rst!ApptDate < Now()
Then
Else
If Not IsNull(rst!ReminderMinutes)
Then
.ReminderOverrideDefault =
True
.ReminderMinutesBeforeStart = rst!ReminderMinutes
.ReminderSet =
True
End If
End If
End If
.Categories = Nz(rst!Categories)
.Save
End With
intCount = intCount + 1
rst.Edit
rst!AddedToOutlook = -1
rst.Update
rst.MoveNext
Loop
Set olAppt =
Nothing
Set olApp =
Nothing
MsgBox intCount & _
" Appointments were added to Outlook.", _
vbInformation
End Sub
Private Sub cmdDeleteSelected_Click()
Dim db As DAO.Database
Dim strSQL As String
Dim strWhere As String
Dim lngRecDeleted As Long
Dim i As Integer
Select Case MsgBox("This action will delete the selected" & _
" Appointments from your Access Database. " _
& vbCrLf & "" _
& vbCrLf & " Are you sure you want to" & _
" permanently delete these Appointments?" _
, vbYesNo Or vbExclamation Or vbDefaultButton2, _
" Delete Database Records?")
Case vbYes
Case vbNo
MsgBox "Deletion has been cancelled! ", vbInformation
Exit Sub
End Select
strSQL = "DELETE tblAppointments.* FROM tblAppointments "
strWhere = "Where tblAppointments.ApptmntID IN("
For i = 0 To Me.lstAppointments.ListCount - 1
If lstAppointments.Selected(i) Then
strWhere = strWhere & lstAppointments.Column(0, i) & ", "
End If
Next i
strWhere = Left(strWhere, Len(strWhere) - 2) & ");"
strSQL = strSQL & strWhere
Set db = CurrentDb()
db.Execute strSQL, dbFailOnError
lngRecDeleted = db.RecordsAffected
MsgBox lngRecDeleted & _
" Appointments were Deleted from the Database.", _
vbInformation
End Sub