robyholmes
Registered User.
- Local time
- Today, 11:45
- Joined
- Mar 2, 2009
- Messages
- 57
Hi, I have posted about this before, but never got anywhere, and seen as I have a bit of time off again, I am back to try again.
I am wanting to find and delete all Appointments with a * or any other character. This is so I can then add them again using VBA code from my database.
So I have this code currently:
Now this was created by someone on here (A long time ago) and was made to find the subject line of a appiontment in my database and update it in outlook if its been updated. The problem is the subject line contains information that may change, and so the appointment wouldn't be able to be found and a copy placed in outlook.
So I thought If I could delete all the appointments in outlook that the database has added (I have another code for this) and place a * or something in the subject, then it could search for that and delete it. Then add them again.
The problem is, this code:
doesn't use a wildcard, it only finds and deletes subjects with * in. I need to search with a wild card after the * so '* Appointment Name' and '* Another Appointment Name' will be deleted.
Thanks
I am wanting to find and delete all Appointments with a * or any other character. This is so I can then add them again using VBA code from my database.
So I have this code currently:
Code:
Public mobjOLA As Outlook.Application
Public mobjNS As Outlook.NameSpace
Public mobjFLDR As Outlook.MAPIFolder
Public mobjAPPT As Outlook.AppointmentItem
'##CDO (COLLABORATION DATA OBJECTS) VARIABLES##
Public dteStart As Date
Public dteEnd As Date
Public bolEvent As Boolean
Public strSubject As String
Public strBody As String
Public strLocation As String
Public strCategory As String
Public strStatus As String
Public bolAddToOutlook As Boolean
Public strFindAppt As String
Public Sub CollectData()
'--------------------------------------------------------------------------------
'This collects the current data from the table and stores it for the loop
'--------------------------------------------------------------------------------
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qrycalendar")
Do Until rs.EOF
With rs
strSubject = !Appt
strLocation = !ApptCat
dteStart = !ApptDate
dteEnd = !ApptEnd
strBody = !ApptNotes
'bolEvent = !AllDayEvent
strCategory = !ApptCat
strStatus = "Free"
bolAddToOutlook = !AddedToOutlook
End With
'SET THE SEARCH VARIABLE
strFindAppt = dteStart & " " & strSubject
'CHECK FOR ENTRIES
If strAddToOutlook = False Then
'ADD THE APPT IF IT NOT SET TO TRUE
AddAppt
rs.Edit
rs!AddedToOutlook = True
rs.Update
Else
End If
rs.MoveNext
Loop
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
MsgBox ("All Appointments are entered into Outlook")
End Sub
Public Sub AddAppt()
Dim outMail As Outlook.AppointmentItem
'set the outlook connection
Set mobjOLA = CreateObject("Outlook.Application")
Set mobjNS = mobjOLA.GetNamespace("MAPI")
mobjNS.Logon , , False, False
Set mobjFLDR = mobjNS.GetDefaultFolder(olFolderCalendar)
On Error Resume Next
Set mobjAPPT = mobjFLDR.Items(strFindAppt)
'check for appointment set. if it is, bail and go to bottom
If Err.Number = 0 Then GoTo FoundObject
'collect the user preferences and add to the appointment
Set outMail = Outlook.CreateItem(olAppointmentItem)
With outMail
.Subject = strFindAppt
.Location = strLocation
.Start = dteStart
.End = dteEnd
.Body = strBody
.AllDayEvent = bolEvent
.Categories = strCategory
.BusyStatus = Free
.Save
End With
'show message if appointment is created
' MsgBox ("Success!! Your appointment has been placed")
Bye:
'close the connection
Set mobjAPPT = Nothing
Set mobjFLDR = Nothing
Set mobjNS = Nothing
Set mobjOLA = Nothing
Exit Sub
'arrive here if the appointment is already set
FoundObject:
MsgBox "Halt!! Appointment Already Placed!" & vbCrLf & _
strFindAppt, _
vbOKOnly, "Information"
GoTo Bye
End Sub
Public Sub RunDeleteAppt()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qrycalendar1")
Do Until rs.EOF
With rs
dteStart = !ApptDate
dteEnd = !ApptEnd
'bolEvent = !AllDayEvent
strSubject = !Appt
strBody = !ApptNotes
strLocation = !ApptLocation
'strCategory = !Category
'strStatus = !Status
bolAddToOutlook = !AddedToOutlook
End With
'SET THE SEARCH VARIABLE
strFindAppt = "*"
'CHECK FOR ENTRIES
If bolAddToOutlook = True Then
'ADD THE APPT IF IT NOT SET TO TRUE
Call DeleteAppt(strFindAppt)
rs.Edit
rs!AddedToOutlook = False
rs.Update
Else
End If
rs.MoveNext
Loop
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
MsgBox ("All Appointments have been removed from Outlook")
End Sub
Public Sub DeleteAppt()
strFindAppt = strFindAppt
' Use this method ONLY if the subject of the
' Appointment Item is known and is UNIQUE.
strFindAppt = "*"
Set mobjOLA = CreateObject("Outlook.Application")
Set mobjNS = mobjOLA.GetNamespace("MAPI")
mobjNS.Logon , , False, False
Set mobjFLDR = mobjNS.GetDefaultFolder(olFolderCalendar)
On Error Resume Next
Set mobjAPPT = mobjFLDR.Items(strFindAppt)
If Err.Number <> 0 Then GoTo CannotFindObject
mobjAPPT.Delete
'MsgBox ("Success!! Your appointment has been deleted")
Bye:
Set mobjAPPT = Nothing
Set mobjFLDR = Nothing
Set mobjNS = Nothing
Set mobjOLA = Nothing
Exit Sub
CannotFindObject:
MsgBox "Cannot find Appointment Item to delete. " & vbCrLf & _
strFindAppt, _
vbOKOnly, "Information"
GoTo Bye
End Sub
Now this was created by someone on here (A long time ago) and was made to find the subject line of a appiontment in my database and update it in outlook if its been updated. The problem is the subject line contains information that may change, and so the appointment wouldn't be able to be found and a copy placed in outlook.
So I thought If I could delete all the appointments in outlook that the database has added (I have another code for this) and place a * or something in the subject, then it could search for that and delete it. Then add them again.
The problem is, this code:
Code:
'SET THE SEARCH VARIABLE
strFindAppt = "*"
'CHECK FOR ENTRIES
If bolAddToOutlook = True Then
'ADD THE APPT IF IT NOT SET TO TRUE
Call DeleteAppt(strFindAppt)
Thanks