Solved

Ms Access/Outlook Appointment system

Posted on 2010-08-20
10
591 Views
Last Modified: 2013-11-27
Hey,

Using help on here i managed to make a script that when i clicked a button in Access it would add an appointment into someones calender, this is the coding ive been using,

Private Sub AddAppt_Click()

 
On Error GoTo ErrorHandler
 
   Dim appOutlook As Outlook.Application
   Dim nms As Outlook.NameSpace
   Dim Appt As Outlook.AppointmentItem
   Dim dteStartTime As Date
   Dim dteEndTime As Date
   
   dteStartTime = CDate(CStr(DateAdd("d", 2, Date)) & " 9:00 AM")
   dteEndTime = CDate(CStr(DateAdd("d", 2, Date)) & " 10:00 AM")
 
   Set appOutlook = GetObject(, "Outlook.Application")
   Set Appt = appOutlook.CreateItem(olAppointmentItem)
   With Appt
      .Subject = Me!Appt
      .Start = dteStartTime
      .End = dteEndTime
      If Not IsNull(Me!ApptLocation) Then .Location = _
      Me!ApptLocation
      If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
      .Recipients.Add (" james.bestwick@example.co.uk")
      .Display
      .Send
   End With
   
ErrorHandlerExit:
   Set appOutlook = Nothing
   Exit Sub
 
ErrorHandler:
   
   If Err.Number = 429 Then
      Set appOutlook = CreateObject("Outlook.Application")
      Resume Next
   Else
      MsgBox "Error No: " & Err.Number _
         & " in CreateApptWithRecipient procedure" _
         & "; Description: " & Err.Description
      Resume ErrorHandlerExit
   End If
   
End Sub

My only problem now is every time i click the button i get an error that comes up saying "Compile error user defined type not defined" it then highlights this part "Dim appOutlook As Outlook.Application" ...... I am using MS Outlook and Access 2003 on a windows 7 operating system.

Thanks
0
Comment
Question by:jdpipes
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 33483136
Hi, jdpipes.

Change

Dim appOutlook As Outlook.Application

to

Dim appOutlook As Object
0
 

Author Comment

by:jdpipes
ID: 33483182
All 3 of these have the same error

   Dim appOutlook As Outlook.Application
   Dim nms As Outlook.NameSpace
   Dim Appt As Outlook.AppointmentItem

if i change all of them to object then i get this error

"Error no: 438 in CreateApptWithRecipient procedure; Description: object doesnt support property or methog"
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33483213
What line does the last error occur on?
0
 
LVL 6

Assisted Solution

by:OxonDev
OxonDev earned 50 total points
ID: 33483247
Hi,

Although BlueDevilFan's suggestion will work I'd also check your references.  You should have one to C:\Program Files\Microsoft Office\Office12\MSOUTL.OLB or similar to use the Outlook Type Library.  

It's also possible that even with a valid reference you'll still get a misleading error message if the file is corrupted.  Try getting this code to work in a new file (using linked tables to access your records).  If the new file works then you've got an issue with the current db.
0
 

Author Comment

by:jdpipes
ID: 33483249
It doesnt give me a line just goes back to the form then shows the message
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 76

Expert Comment

by:David Lee
ID: 33483288
OxonDev is correct.  You can add a reference.  I didn't suggest that because in my opinion it's a better practice to use late binding and avoid reference issues, especially if the code is going to be distributed.  I don't see now the code can generate a "object doesn't support property or method" compile error when the objects are typed.  That implies that it knows what methods are defined for each object which it cannot know when the object type isn't specified.  
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 50 total points
ID: 33483349
You'll also have to define your constants. You use this one:

olAppointmentItem

If you have a reference to the Outlook library it'll work. If you remove the reference, it won't work. You can define them in the General Declarations section somewhere:

Public Const ac_olAppointmentItem = 100 '/or whatever value is needed

note the different spelling - I've added "ac_" to the beginning, therefore you'd have to change your code to use that value instead of olAppointmentItem

And I agree with BlueDevilFan - one of the points of using late binding is to NOT have references, therefore using OxenDev's advice to add a reference to the TypeLib would somewhat defeat that purpose.
0
 

Author Comment

by:jdpipes
ID: 33483363
ive changed it about and played with it and came up with this which works can anyone see any problems?

Private Sub AddAppt_Click()

Dim strMsg As String
Dim strName As String
On Error Resume Next


strName = Me!Recipients

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objDummy = objApp.CreateItem(olMailItem)
Set objRecip = objDummy.Recipients.Add(strName)
objRecip.Resolve
If objRecip.Resolved Then
On Error Resume Next
Set objFolder = objNS.GetSharedDefaultFolder(objRecip, 9)
If Not objFolder Is Nothing Then
Set objAppt = objFolder.Items.Add
If Not objAppt Is Nothing Then
With objAppt
.Subject = Me!Appt
.Start = Me!ApptDate & " " & Me!ApptTime
.Duration = Me!ApptLength
.Location = Me!ApptLocation
.Body = Me!ApptNotes
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
.Save
End With
End If
End If
Else
MsgBox "Could not find " & Chr(34) & strName & Chr(34), , _
"User not found"
End If

Set objApp = Nothing
Set objNS = Nothing
Set objFolder = Nothing
Set objDummy = Nothing
Set objRecip = Nothing
Set objAppt = Nothing
End Sub
0
 
LVL 76

Accepted Solution

by:
David Lee earned 400 total points
ID: 33483370
Looks good to me.
0
 
LVL 84
ID: 33484498
I don't see where you've defined:

olMailItem

although you may have defined it in a separate module. If you have not, then be aware that you will need to maintain your reference to the Outlook library, which can cause issues when deploying if you must support multiple versions of Outlook.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now