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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CODE PROBLEM WITH A COMMAND BUTTON 1

Status
Not open for further replies.

greeneyerat

Technical User
Oct 15, 2003
26
0
0
US
I have a main form, in which I have a subfrmAppointments that has a control button that is suppose to send the actual appointment to Outlook but I get the following message:

"user defined type not defined" and the following is the code line highlighted.

Dim objOutlookApplication As Outlook.Application

Following is the code I have written:

Private Sub CmdAddAppt_Click()
On Error GoTo Add_Err

'Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord

'Exit the procedure if appointment has been added to Outlook.
If Me!ApptAddedToOutlook = True Then
MsgBox "This appointment is already added to Microsoft Outlook."
Exit Sub
'Add a new appointment.
Else
Dim objOutlookApplication As Outlook.Application
Dim objAppt As Outlook.AppointmentItem

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

With objAppt
.Start = Me!ApptDate & " " & Me!ApptTime
.Duration = Me!ApptLength
'.Subject = Me!Appt

If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation
If Not IsNull(Me!ApptSubject) Then .Subject = Me!ApptSubject
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ApptReminderMin
.ReminderSet = True
End If

objAppt.Save

End With
'Release the AppointmentItem object variable.
Set objAppt = Nothing
End If

'Release the Outlook object variable.
Set objOutlook = Nothing

'Set the AddedToOutlook flag, save the record, display a message.
Me!ApptAddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"

Exit Sub

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

Please Help!!

Thanks!!
 


Just for grin's try compiling you MDB. Do you get the same error message???

It may be a reference problem.

 
You have to reference the Microsoft Outlook Object Library:
When in VBE, menu Tools -> References ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
...and FYI, ALL CAPS IS CONSIDERED SHOUTING AND NOT A RECOMMENDED WAY TO START A THREAD! [hammer]

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top