Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to Outlook

Status
Not open for further replies.

McFestoe

Technical User
Dec 16, 2003
145
GB
Having a problem getting access to outlook, the problems starts with a broken reference or project, which iam unsure about.

Set objOutlook = CreateObject("Outlook.Application")
Set objAppt = objOutlook.CreateItem(olAppointmentItem)

The problem is with the olAppointentItem which seams to cause the errors, anybody done access to outlook and can help me understand what olAppointment is looking for or what the reference it is looking for.

Thanks
 
Either references outlook (menu Tools -> References ...)
or use the true value of the constant (Const olAppointmentItem = 1)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the reply, had a look a tried the references and still cant get past that line, still getting

Compile Error, cant find project or libary.

I have the references for outlook set up and also DAO 3.6, is olAppointmentItem looking for something, i thought this line was to create an appointment item.

Thanks
 
Anybody help me out, i have looked at references and think i have all them installed, but still the code stops at

Set objAppt = objOutlook.CreateItem(olAppointmentItem)

Flagging the olAppointmentItem

Cant see whats wrong, any suggestions.


Private Sub Command15_Click()


On Error GoTo Add_Err

DoCmd.RunCommand acCmdSaveRecord

If Me!addedtooutlook = True Then
MsgBox "This appointment is already added to Microsoft Outlook"
Exit Sub

Else
Dim objOutlook As Outlook.Application
Dim objAppt As Outlook.AppointmentItem

Set objOutlook = CreateObject("Outlook.Application")
Set objAppt = objOutlook.CreateItem(olAppointmentItem)

With objAppt
.Start = Me!DateofVisit & " " & Me!Time_Booked
.Subject = Me!ReasonforVisit


If Not IsNull(Me!address1) Then .Location = Me!address1

.ReminderSet = True


.Save

End With

Set objAppt = Nothing
End If

Set objOutlook = Nothing

Me!addedtooutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"

Exit Sub

Add_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub

 
Still trying to get this working but still the same problems.Any pointers
 
PHV recommended using the true value in a post dated 19 Jan 07 16:31. Have you tried that?
 
Understand that olAppointmentItem is a constant, i.e. it just stands for a number, so you could just put the number in instead (as per PHV's suggestion). Better yet, create your own constant and set it to that number (so you won't be using "magic" numbers in your code).

 
Thanks for the reply,

Remou, i did try PHVs suggestion and it still would not work, i will try it again now and post the outcome.

Joe at Work, Thanks for reply will have a look again.
 
I ran your code on my setup with no problems. The only thing I altered, was the names of the form controls. The code seems to be OK, so you probably have to look elsewhere for what is causing this. Have you tried running it on other PCs?

Have you considered trying going late bound? That would mean removing the reference to the Microsoft Outlook library, alter the declarations to

Dim objOutlook As Object ' Outlook.Application
Dim objAppt As Object ' Outlook.AppointmentItem

and change the olAppointmentItem to the litteral 1

I don't know what to suggest, but from the top of my head, at least before trying to reinstall Office, try importing all objects to a new database, see if that helps. If not, then try the Detect and Repair option on the Help menu of recent versions.

Roy-Vidar
 
Roy

Thans for the post, i have got it working with the following code.

I have transfered it to another PC and need to set the references up again, is there anyway to get access to install the references automatically.

Private Sub Command15_Click()


On Error GoTo Add_Err

DoCmd.RunCommand acCmdSaveRecord

If Me!addedtooutlook = True Then
MsgBox "This appointment is already added to Microsoft Outlook"
Exit Sub

Else
Dim objOutlook As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Const olAppointmentItem = 1

Set objOutlook = CreateObject("Outlook.Application")
Set objAppt = objOutlook.CreateItem(olAppointmentItem)


With objAppt
.Start = Me!apptdate & " " & Me!apptTime
.Subject = Me!ReasonforVisit
.Body = Me!AddressLine1
.Body = Me!AddressLine2
.Body = Me!AddressLine3
.Body = Me!Postcode

If Not IsNull(Me!AddressLine1) Then .Location = Me!AddressLine1 & " " & Me!Postcode

.ReminderSet = True


.Save

End With

Set objAppt = Nothing
End If

Set objOutlook = Nothing

Me!addedtooutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"

Exit Sub

Add_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
 
Hi, McFestoe,

Just curious, is this code really giving you the appointment body text you want?
Code:
.Body = Me!AddressLine1
.Body = Me!AddressLine2
.Body = Me!AddressLine3
.Body = Me!Postcode
Seems like each statement would successively replace the body text, not append it. I think I would concatenate it like this:
Code:
.Body = Me!AddressLine1 & vbCrLf _
& Me!AddressLine2 & vbCrLf _
& Me!AddressLine2 & vbCrLf _
& Me!Postcode
HTH,

Ken S.
 
Eupher

Thanks i had a late night last night reading up i did wonder about about cbCrLf to add a new line.

Learning alot with thanksto you guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top