Delete an Outlook appointment from Access

  • Thread starter Thread starter Margamo
  • Start date Start date
M

Margamo

Could someone please look at my code, I can direct the program to look
at the Access text box.

Private Sub cmdDeleteAppt_Click()

Dim olapp As Outlook.Application
Dim olfolder As Outlook.MAPIFolder
Dim colCalendar As Outlook.Items
Dim outappt As Outlook.AppointmentItem
Dim txtFind As String

Set olapp = CreateObject("Outlook.Application")
Set olfolder = olapp.GetNamespace("Mapi").GetFolderFromID("00000000F31B77B77395D5119EEB0000F805AF8F010055AD18F0018A874D86AA178D9A7B20BD000005ACB6F10000")
Set colCalendar = olfolder.Items

Forms!frmRecruitment.txtFullname2.SetFocus
txtFind = Forms!frmRecruitment.txtFullname2.Text
On Error GoTo cmdDeleteAppt_Err
outappt = colCalendar.Find([txtFind])


If Not outappt Is Nothing Then
outappt.Delete
End If

Set olapp = Nothing
Set olfolder = Nothing
Set colCalendar = Nothing
cmdDeleteAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End Sub

Thanks,
Margamo
 
Your syntax for the Items.Find method is incomplete. You're not telling
Outlook what field to look in. You need to build a search string that
includes the field name. I suspect you want to search on the Subject of the
appointments. In that case:

strFind = "[Subject] = " & Chr(34) & [txtFind]) & Chr(34)
Set outAppt = colCalendar.Find(strFind)
 
Oops. Take out the extra ) in the strFind statement.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Sue Mosher said:
Your syntax for the Items.Find method is incomplete. You're not telling
Outlook what field to look in. You need to build a search string that
includes the field name. I suspect you want to search on the Subject of the
appointments. In that case:

strFind = "[Subject] = " & Chr(34) & [txtFind]) & Chr(34)
Set outAppt = colCalendar.Find(strFind)
Margamo said:
Could someone please look at my code, I can direct the program to look
at the Access text box.

Private Sub cmdDeleteAppt_Click()

Dim olapp As Outlook.Application
Dim olfolder As Outlook.MAPIFolder
Dim colCalendar As Outlook.Items
Dim outappt As Outlook.AppointmentItem
Dim txtFind As String

Set olapp = CreateObject("Outlook.Application")
Set olfolder =
olapp.GetNamespace("Mapi").GetFolderFromID("00000000F31B77B77395D5119EEB0000
F805AF8F010055AD18F0018A874D86AA178D9A7B20BD000005ACB6F10000")
Set colCalendar = olfolder.Items

Forms!frmRecruitment.txtFullname2.SetFocus
txtFind = Forms!frmRecruitment.txtFullname2.Text
On Error GoTo cmdDeleteAppt_Err
outappt = colCalendar.Find([txtFind])


If Not outappt Is Nothing Then
outappt.Delete
End If

Set olapp = Nothing
Set olfolder = Nothing
Set colCalendar = Nothing
cmdDeleteAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End Sub

Thanks,
Margamo
 
Now I don't get an error message but it doesn't delete the appointment
either.
Can you please tell what is wrong with my code?
Thanks,
Margamo

Private Sub cmdDeleteAppt_Click()

Dim olapp As Outlook.Application
Dim olfolder As Outlook.MAPIFolder
Dim colCalendar As Outlook.Items
Dim outappt As Outlook.AppointmentItem
Dim txtFind As String
Dim strFind As String
Set olapp = CreateObject("Outlook.Application")
Set olfolder =
olapp.GetNamespace("Mapi").GetFolderFromID("00000000F31B77B77395D5119EEB
0000F805AF8F010055AD18F0018A874D86AA178D9A7B20BD000005ACB6F10000")
Set colCalendar = olfolder.Items
Forms!frmRecruitment.txtFullname2.SetFocus
txtFind = Forms!frmRecruitment.txtFullname2.Text
strFind = "[Subject] = " & ([txtFind]) & Chr(32) & ([LastFour])

Set outappt = colCalendar.Find(strFind)

On Error GoTo cmdDeleteAppt_Err

If Not outappt Is Nothing Then
outappt.Delete
End If
Set olapp = Nothing
Set olfolder = Nothing
Set colCalendar = Nothing
Exit Sub
cmdDeleteAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
End Sub
 
If txtFind is a variable name, then you don't need brackets around it. You
must, however, surround it with quotation marks, as my earlier example
showed:

strFind = "[Subject] = " & Chr(34) & txtFind & Chr(34)

What is [LastFour]?

I would strongly suggest that you use a Debug.Print or MsgBox statement to
check the value of strFind and check whether the statement setting outappt
returns Nothing.
 
I figured out the problem, I was using a different subject than the one
I used to add the appointment.
Thanks Sue, for the help. Sorry to have bothered you with the a problem
I should have done more research on my own.
 
How do I modify this code to look at a different users calendar and delete the appointment?
 
Back
Top