I am trying to delete an outlook appointment based upon the value of variables for Location, Start Date, Start Time & Name (Subject)
I am at a loss as where to start on declarations for Outlook Objects. I found some code on the Web and tried to alter it. Could you please help with the declarations for finding the appointment in Outlook. My rubbish attempt at coding is as follows:- -
Dim olApp As Outlook.Application
-
Dim objAppts As Outlook.AppointmentItem
-
-
Dim AP_Date As Date
-
Dim AP_Start_Time As Date
-
Dim AP_Location As String
-
Dim AP_Subject As String
-
-
Dim OutlookStartTime As Date
-
Dim OutlookLocation As String
-
Dim OutlookSubject As String
-
Dim sFilter As Variant
-
-
AP_Date = Module1.oldDate
-
AP_Start_Time = Module1.oldStart
-
AP_Location = Module1.oldLocation
-
AP_Subject = Module1.oldName
-
-
OutlookStartTime = CDate(AP_Date & " " & AP_Start_Time)
-
OutlookLocation = (AP_Location)
-
OutlookSubject = (AP_Subject)
-
-
Set olApp = CreateObject("Outlook.Application")
-
Set objAppointments = objAppts.DeleteItem(olAppointmentItem)
-
-
sFilter = "[Start] = '" & OutlookStartTime & _
-
"' And [Location] = '" & OutlookLocation & "' " & _
-
" And [Subject] = '" & OutlookSubject & "'"
-
-
Set objAppointments = objAppointments.Items.Find(sFilter)
-
-
If Not TypeName(objAppointments) = "Nothing" Then
-
MsgBox ("Appointment Found")
-
'objAppointment.Delete
-
End If
-
-
Set objAppointments = Nothing
-
Set objAppts = Nothing
-
Exit Sub
If I can have some help on declaration I could possibly work out the rest.
Many thanks in advance
20 17881 NeoPa 32,568
Recognized Expert Moderator MVP
Cyd, you need to post the question with care. Not just dump code in and expect us to work out what the question should be. Describe what you're actually doing and where you get stuck. The declarations seem fine to me, but you don't really provide a question to work with.
General tips on items and how they fit into the Outlook class structure can be found by using Object Explorer within the VBA IDE. You can do it from Access too, but probably easier to do it in the native application. See Debugging in VBA for how to invoke and have a play.
Ok NeoPa Sorry if I am not asking correctly. I will try to explain better.
I have successfully managed to create appointments in Outlook using the following sub:- -
'Add a new appointment.
-
-
Dim objOutlook As Outlook.Application
-
Dim objAppt As Outlook.AppointmentItem
-
'Dim objRecurPattern As Outlook.RecurrencePattern
-
-
Set objOutlook = CreateObject("Outlook.Application")
-
Set objAppt = objOutlook.CreateItem(olAppointmentItem)
-
-
With objAppt
-
.Start = Me!BookStartDate & " " & Me!BookTime
-
.Duration = Me!TImeConversion
-
.Subject = Me!BookName
-
.Location = Me!BookLocation
-
If Not IsNull(Me!BookNotes) Then .Body = Me!BookNotes
-
-
.Save
-
.Close (olSave)
-
End With
-
'Release the AppointmentItem object variable.
-
Set objAppt = Nothing
-
-
-
'Release the Outlook object variable.
-
Set objOutlook = Nothing
-
MsgBox " Changes have been Saved and New Appointment Added to Outlook!"
I now wish to turn this around so that find an appointment by using the unique identfiers which are Location, StartDate, BookTime, Location and BookName. I want to delete this appointment if found.
I am unsure as to how I call outlook to find and delete the appointment using the above variables as I do not know the correct variable decalartions for Outlook (IE Setting Object required)
I hope this clarifies my position. I can see now that giving you code that is not working has confused things. When I try to run the delete sub I keep getting a mismatch error on declaring the Start date as both StartDate & StartTime. I do not actually understand why we cannot set the date and time separately.
NeoPa 32,568
Recognized Expert Moderator MVP
It wasn't the code that confused things. It was the lack of any discernable question or even explanation of why the code is there at all. I'm sure I've linked you before to how to ask questions and what to do when posting code that isn't working as expected. The line number and error message are necessary as well as explaining what is going on. All these important elements are again missing from the question. You should also include the code that defines the procedure like the header so that when you refer to a ' Delete Sub' I don't go through all the code again just to find that nothing is identified as a ' Delete Sub'. I guess it's your first bit of code, but I frankly ought not to be spending my time guessing what you should be telling me. I guess also you're referring to line #19, but all the lines are numbered. If you use the numbers that are provided I don't need to try to read your mind.
Assuming then, that it is indeed line #19 of your first posted code that is causing some unspecified problem, I would suggest that you breakpoint your code at line #19 and see what the string representations are of [AP_Date] and [AP_Start_Time] ( Debugging in VBA may help with this). I have no way of knowing what data you have in there so I can only guess. If they are a valid date and time stored in Date format though, you may get away with : - OutlookStartTime = AP_Date + AP_Start_Time
Remember, Include the procedure declaration when posting a procedure (Not always necessary for small snippets but when posting a whole procedure it's very important). Especially if you want to refer to the named procedure in your explanation.
Back to this problem having first worked out how to capture pre-edit data.
My problem here is with lack of knowledge on the syntax required to connect to Outlook and find an appointment for deletion. I have comented the code so that you can see what I am trying to achieve here. Am getting a complie error on GetdefaultFolde r and I am not sure of my logic for the declarations surounding Outlook.
I hope this question makes sense as I think you can see what I am trying to do within the code. All the record field variables work fine and the values are as expected. My major problem is trying to understand the object requirements for OutLook.
My code is as follows:- -
Delete_Old_Appointment:
-
' The Following variable assignments will pick-up the old booking data prior to the change in order
-
' to find and delete an Outlook booking. Variables have been caputured by the Sub Form_Current()procedure
-
' and declared Public in the basMyEmpID Standard Code Module.
-
-
Dim goldLocation As String
-
Dim goldStart As Date
-
Dim goldDate As Date
-
Dim goldName As String
-
-
goldLocation = basMyEmpID.gstroldLocation
-
goldStart = basMyEmpID.gdteoldStart
-
goldDate = basMyEmpID.gdteoldDate
-
goldName = basMyEmpID.gstroldName
-
-
MsgBox (goldLocation & goldStart & goldDate & goldName) ' Take Out when fully developed
-
-
' Connection to Outlook Variables
-
-
Dim objOlook As outlook.Application
-
Dim objFolder As outlook.MAPIFolder
-
Dim objOAppt As outlook.AppointmentItem
-
Dim objOItems As outlook.Items
-
Dim appStart As Variant
-
Dim strFilter As String
-
-
Set objOlook = CreateObject("Outlook.Application")
-
Set objFolder = objOlook.GetNamespace("MAPI").GetDefaultFolder
-
Set objOAppt = objFolder.Items
-
Set objOItems = objOAppt.Item
-
-
' Set the Filter String to find Outlook Appointment
-
-
appStart = goldDate & " " & goldStart ' Joins Date & Time together for OLook
-
MsgBox (appStart)
-
strFilter = "[Start]= " '" appStart & "'" & " And [Location]= " & "'" & goldLocation & "'" & " And [Subject]= " & "'" & goldName & "'"
-
-
' Find the outlook appointment based upon the above strFilter condition
-
-
Set objOAppt = objOItems.Find(strFilter)
-
MsgBox (strFilter)
-
' objOAppt.Delete
-
'.Close (olSave)
-
'Release the AppointmentItem object variable.
-
Set objOAppt = Nothing
-
-
'Release the Outlook object variable.
-
Set objOlook = Nothing
-
MsgBox (" Old Appointment Has been deleted in Outlook!")
-
GoTo Add_New_Appointment
-
Exit Sub
Could you please advise how the outlook objects should look?
NeoPa 32,568
Recognized Expert Moderator MVP
I'm still struggling to understand what you're asking for Cyd. Still no line numbers to refer to. However, my best guess is that you're asking about the code in lines #20 through #30, as these seem to declare and set the Outlook objects.
Lines #20 through #25 :
objOlook, objFolder, objOAppt, objOItems and strFilter all appear to be declared perfectly. appStart is declared as a Variant, no doubt in line with what's been said earlier, but the way it is assigned (Line #34) stops any possibility of its being used to determine if a value exists or not as a Null. Line #34 will always return a valid string - in all circumstances.
Lines #27 through #30 :
#27 and #28 look fine, but lines #29 and #30 appear to be assigning each other's values. IE They should probably read : - Set objOItems = objFolder.Items
-
Set objOAppt = objOItems(???)
Of course you probably don't know yet which item in objOItems() to select.
Line #36 (Bonus) :
It is not necessary to concatenate literal strings together using the format "xxx" & "yyy". The result is much easier and more logically achieved by simply using a single string "xxxyyy". - strFilter = "[Start]= '" & appStart & "' AND [Location]= '" & goldLocation & "' AND [Subject]= '" & goldName & "'"
Sorry again if I am confusing you. I am realy struggling with the logic of declaring Outlook objects when I want to find an appointment (rather than create one).
I do not understand how to declare the Set obj variables I am afraid.
I have connected successfully to create an appointment but do not know what I need to do to just open the calendar and find one.
Is there not a generic set of object setting to open appointments to find one.?
I suppose my question should be
How do you set the objects to connect to outlook in order to find an appointment to delete.? I have played around so much now I am totally confused. when I search the web I cannot find a diffinitive answer and have seen so many variations....n on of which answer my basic problem.
I have noted where you suggest change and have done so but what would I set objOAppt to....I have not a clue I am afraid
NeoPa 32,568
Recognized Expert Moderator MVP
It's so much easier to work with posts that are as clear as this one Cyd. Let's see what we can do with it.
First let's check out Application Automation for some of the basics. Frankly, your basics are already not too far off the mark, but it doesn't hurt to synchronise.
Assuming you're up on all the points from there then, your code seems to get the Outlook.Applica tion object ok (Remember it is not visible at this stage). Next it gets the default MAPI folder (This will probably be the Inbox folder). If you want the Calendar folder specifically, then you can use either of : - Set objFolder = objOlook.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
-
Set objFolder = objOlook.GetNamespace("MAPI").Folders("Calendar")
After that your new code is fine for setting the Items object but then I suspect you'd need to use its Find() method. - Set objOItems = objFolder.Items
-
Set objOAppt = objOItems.Find(strFilter)
Of course, your code doesn't currently have any strFilter set, so you should probably be looking to set it up first, to match your requirements. At this point I need to point you at the Context-Sensitive Help article again as you need to look for yourself. There is a (pretty large) list in there of the available fields that can be matched and it seems none of the values you are searching on have a match to any of the available fields.
NeoPa 32,568
Recognized Expert Moderator MVP
It appears I misread the help page. The list was one of invalid properties to check rather than one of the only valid properties. Nevertheless, look through it yourself for most benefit. It gives some examples and how to avoid the more obvious errors.
NB. Choose (click on) Find method as it applies to the Items object.
Hi NeoPa,
Have looked at all of your recomendation and am still no wiser for my dilema I am afraid. I have already been successful in Creating an appointment on Outlook and there are many items on the web dealing with creation. However, I cannot find any items dealing specifically with deleting an appointment which I find strange as I would have thought this was as normal as Creating.
My Creation script does not bother with MAPI as we are on a single laptop. When I have tried to set MAPI variables for deletion it complains so I have left this out.
I have reached the stage where I have used the same 2 variables for Creating access to Outlook and Appointments as I have used when I add an appointment (the add works fine). This is the coding I have for the deletion now -
Dim objOlook As Outlook.Application
-
Dim objOAppt As Outlook.AppointmentItem
-
Dim objOItem As Outlook.AppointmentItem
-
Dim appStart As Variant
-
Dim strFilter As String
-
-
-
Set objOlook = CreateObject("Outlook.Application")
-
Set objOItem = objOlook.CreateItem(olAppointmentItem)
-
-
' Set the Filter String to find Outlook Appointment
-
-
appStart = goldDate & " " & goldStart ' Joins Date & Time together for OLook
-
-
-
strFilter = "[Start]= '" & appStart & "' AND [Location]= '" & goldLocation & "' AND [Subject]= '" & goldName & "'"
-
If IsNull(strFilter) Then
-
MsgBox ("No App")
-
Else
-
If IsNull(objOAppt) Then
-
MsgBox ("No OL Appointement found")
-
Else
-
Set objOAppt = objOItem.Items.Find(strFilter)
-
'objOAppt.Delete
-
MsgBox (objOAppt)
-
End If
-
End If
-
On running the code it complains at the
"Set objOAppt = objOItem.Items. Find(strFilter) " giving an error 438 - Object doesnt support this method or property
I have trapped the variables up to this line and they appear to be OK.
Would you have any ideas on this please. I still think it is my Syntax and, in particular, the use of the .Find statement. Had tried to use your suggestion earlier and it did not like this at all. The Context help does not really help I am afraid.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Akira |
last post by:
Could someone tell me how to send outlook appointment email from asp
page?
I would like appointment email just like one outlook can send out.
I tried to look for an answer for this, but it seems exchange server
has to be installed on web server if I want to use the following
code??
Is there way to send outlook appointment email without using
outlook.Application object?
If not, how can I make the code below work since we have separate...
|
by: Sam |
last post by:
My db looks after the hiring and lending of equipment, the form which books
out equipment hired prints a signout sheet and automatically inserts an
appointment into outlook advising the operator on the due date that a
particular hire is due.
I have used microsoft's automated appointment code to do this, what I would
also like the code to do is to email an appointment to the person hiring the
gear.
Knowing that you can email an...
|
by: Kamyk |
last post by:
Hello all!
I have the following problem. I know how to create a mail in VB with a
subject and people to send, but is it possible to create an Outlook
appointment in VB, if it is possible, please be so kind and give me some
example?
Thank you in advance
Marcin from Poland
|
by: Kamyk |
last post by:
Hello all!
I have created a function in VB which generate appointment in Outlook.
Everything is OK, except one thing. I cannot send it automatically using a
button in Access, because I don`t know what is the code to send it
automatically. I noticed that if I click on Calendar>"click on selected
appointment">menu>Appointment>Invite Atendees everything is going well and
this appointment is sent to attendees given on the list.
My question...
|
by: Georges |
last post by:
Hi,
Can anyone help me with this.
I would like to create outlook appointment from a web application.
I tried to look at the CDO, WebDAV and MAPI documentations without success.
what is the best way of creating an appointment?
We are using W2000, Office 2000, Exchange 2000 and .net framework.
any ideas would be appreciated. (code example more than welcome)
cheers,
George
| |
by: chuckdfoster |
last post by:
Is there a way to create an New Outlook Appointment from an ASP.NET
application? I would also need to check if Outlook is running first. Any
suggestions, advice?
|
by: Ori :) |
last post by:
I am writing an application to retrieve appointments from Outlook, I have the appointment items sorted by
"Start" field and now I want to find the first record which's "Start" value is later than now (future appointment
The relevant piece of my current code
Dim oCalendar As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar
Dim oItems As Outlook.Items = oCalendar.Item
oItems.Sort("Start"...
|
by: berend.kapelle |
last post by:
Hi,
i found this code from outlookcode.com
http://www.outlookcode.com/codedetail.aspx?id=139
Its written in VB, and i have some problem porting it to C#.
The problem is getting the right appointment. An Exception occurs in
this line:
MAPI.Field oField = (MAPI.Field) oFields.get_Item(CdoAppt_Colors,
CdoPropSetID1);
|
by: keri |
last post by:
Hi everyone,
I have searched for info on this topic but have not found anything.
Basically I have a db that posts appointments to outlook. I would like
to be able to set all of the outlook appointment labels (names and
colour shading) from my db then assign them to the appointments I put
into outlook.
It seems that this can not be done simply from VB but if anyone can
give me some pointers on where I can start to do this, or anything I
|
by: Vic Rensburg |
last post by:
Dear All,
I have a Call Logger database with a scheduler function.
I've managed to book the appointments and set reminders in Outlook 2007 via access vba, but I'ma bit stuck in calling the appointment information via using the subject and then amending the date and time.
I would really appreciate if you couldprovide some sample code of how this possibly could be achieved. Please help.
Many thanks,
Vic
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |