C
Chris O''''Neill
I wasn't sure whether to post this here or one of the Outlook forums???
Let's try here first...
I have created a subroutine to send an appointment to Outlook. It seems to
work (i.e. no errors when I run it), but now I'm having a problem with
Outlook. Here's what happens...
1. The subroutine in my program seems to run okay.
2. The next time I open up Outlook, it stays loaded for a few moments
(maybe 10-15 seconds?) and then disappears.
3. When I open up Outlook again, it stays loaded. However, when I try to
double click on one of the appointments I just added I get the following
error message:
"Can't open this item. Out of memory or system resources. Close some
windows
or programs and try again."
I keep getting this error no matter what I do (close and restart Outlook,
close all other windows and restart Outlook, reboot and restart Outlook).
Appointments created manually in Outlook don't give this error message.
So, there must be something wrong with my code or the way I'm creating the
appointment???? Here's the code. Any assistance provided would be greatly
appreciated!
Regards, Chris
Private Sub cmdSchedule_Click()
On Error GoTo ERR_cmdSchedule_Click
Dim strProblem As String
Dim strSubject As String
Dim strLocation As String
Dim prompt As String
Dim title As String
Dim style As Integer
Dim intDuration As Integer
Dim intNotReady As Integer
Dim intHours As Integer
Dim intMinutes As Integer
Dim intReminder As Integer
'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!chkAddedToOutlook = True Then
MsgBox "This appointment is already added to Microsoft Outlook"
Else
strSubject = Me.txtServiceType & ": " & Me.txtEventType & " - " &
Me.txtEventName
If IsNull(Me.txtEventCityStateProv) Then
strLocation = Nz(Me.txtEventAddress, "")
Else
strLocation = Me.txtEventAddress & ", " & Me.txtEventCityStateProv
End If
intHours = Hour([Forms]![frmEvents]![txtEndTime]) -
Hour([Forms]![frmEvents]![txtStartTime])
intMinutes = Minute([Forms]![frmEvents]![txtEndTime]) -
Minute([Forms]![frmEvents]![txtStartTime])
intDuration = intMinutes + (intHours * 60)
intNotReady = 0
If IsNull(Me.txtServiceType) Then
intNotReady = 1
strProblem = strProblem & "Missing Service Type!!" & vbCrLf
End If
If IsNull(Me.txtEventType) Then
intNotReady = 1
strProblem = strProblem & "Missing Event Type!!" & vbCrLf
End If
If IsNull(Me.txtEventName) Then
intNotReady = 1
strProblem = strProblem & "Missing Event Name!!" & vbCrLf
End If
If strLocation = "" Then
intNotReady = 1
strProblem = strProblem & "Missing Location!" & vbCrLf
End If
If intDuration = 0 Then
intNotReady = 1
strProblem = strProblem & "Missing Duration!" & vbCrLf
End If
If intNotReady <> 0 Then
prompt = "This event cannot be scheduled for the following
reason(s):" & vbCrLf & vbCrLf & strProblem
style = vbOKOnly + vbCritical
title = "Can't Schedule!"
MsgBox prompt, style, title
Else
'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!txtStartDate & " " & Me!txtStartTime
.Duration = intDuration
.Subject = strSubject
If Not IsNull(Me!txtEventDescription) Then .Body =
Me!txtEventDescription
If Not IsNull(strLocation) Then .Location = strLocation
intReminder = InputBox("How many days reminder would you
like?", "Reminder?", 1)
.ReminderMinutesBeforeStart = intReminder * 1440
.ReminderSet = True
' End If
If Me.txtStartDate <> Me.txtEndDate Then
Set objRecurPattern = .GetRecurrencePattern
With objRecurPattern
.RecurrenceType = olRecursWeekly
'*************************
' Need to figure out how to calculate number of
weeks between start and end dates
' and insert here as intInterval. For now, we just
leave it as 1 week
'*************************
.Interval = 1
'Once per week
.PatternStartDate = Me.txtStartDate
.PatternEndDate = Me.txtEndDate
End With
' Now that we're done with obJRecurPattern, set it to
nothing
Set objRecurPattern = Nothing
End If
.Save
.Close (olSave)
End With
End If
'Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
End If
Exit_cmdSchedule_Click:
' Release the Outlook object variables
' Note: I put this here so that it would run even if there's a error
Set objAppt = Nothing
Set objOutlook = Nothing
Exit Sub
ERR_cmdSchedule_Click:
MsgBox Err.Description
Resume Exit_cmdSchedule_Click
End Sub
Let's try here first...
I have created a subroutine to send an appointment to Outlook. It seems to
work (i.e. no errors when I run it), but now I'm having a problem with
Outlook. Here's what happens...
1. The subroutine in my program seems to run okay.
2. The next time I open up Outlook, it stays loaded for a few moments
(maybe 10-15 seconds?) and then disappears.
3. When I open up Outlook again, it stays loaded. However, when I try to
double click on one of the appointments I just added I get the following
error message:
"Can't open this item. Out of memory or system resources. Close some
windows
or programs and try again."
I keep getting this error no matter what I do (close and restart Outlook,
close all other windows and restart Outlook, reboot and restart Outlook).
Appointments created manually in Outlook don't give this error message.
So, there must be something wrong with my code or the way I'm creating the
appointment???? Here's the code. Any assistance provided would be greatly
appreciated!
Regards, Chris
Private Sub cmdSchedule_Click()
On Error GoTo ERR_cmdSchedule_Click
Dim strProblem As String
Dim strSubject As String
Dim strLocation As String
Dim prompt As String
Dim title As String
Dim style As Integer
Dim intDuration As Integer
Dim intNotReady As Integer
Dim intHours As Integer
Dim intMinutes As Integer
Dim intReminder As Integer
'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!chkAddedToOutlook = True Then
MsgBox "This appointment is already added to Microsoft Outlook"
Else
strSubject = Me.txtServiceType & ": " & Me.txtEventType & " - " &
Me.txtEventName
If IsNull(Me.txtEventCityStateProv) Then
strLocation = Nz(Me.txtEventAddress, "")
Else
strLocation = Me.txtEventAddress & ", " & Me.txtEventCityStateProv
End If
intHours = Hour([Forms]![frmEvents]![txtEndTime]) -
Hour([Forms]![frmEvents]![txtStartTime])
intMinutes = Minute([Forms]![frmEvents]![txtEndTime]) -
Minute([Forms]![frmEvents]![txtStartTime])
intDuration = intMinutes + (intHours * 60)
intNotReady = 0
If IsNull(Me.txtServiceType) Then
intNotReady = 1
strProblem = strProblem & "Missing Service Type!!" & vbCrLf
End If
If IsNull(Me.txtEventType) Then
intNotReady = 1
strProblem = strProblem & "Missing Event Type!!" & vbCrLf
End If
If IsNull(Me.txtEventName) Then
intNotReady = 1
strProblem = strProblem & "Missing Event Name!!" & vbCrLf
End If
If strLocation = "" Then
intNotReady = 1
strProblem = strProblem & "Missing Location!" & vbCrLf
End If
If intDuration = 0 Then
intNotReady = 1
strProblem = strProblem & "Missing Duration!" & vbCrLf
End If
If intNotReady <> 0 Then
prompt = "This event cannot be scheduled for the following
reason(s):" & vbCrLf & vbCrLf & strProblem
style = vbOKOnly + vbCritical
title = "Can't Schedule!"
MsgBox prompt, style, title
Else
'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!txtStartDate & " " & Me!txtStartTime
.Duration = intDuration
.Subject = strSubject
If Not IsNull(Me!txtEventDescription) Then .Body =
Me!txtEventDescription
If Not IsNull(strLocation) Then .Location = strLocation
intReminder = InputBox("How many days reminder would you
like?", "Reminder?", 1)
.ReminderMinutesBeforeStart = intReminder * 1440
.ReminderSet = True
' End If
If Me.txtStartDate <> Me.txtEndDate Then
Set objRecurPattern = .GetRecurrencePattern
With objRecurPattern
.RecurrenceType = olRecursWeekly
'*************************
' Need to figure out how to calculate number of
weeks between start and end dates
' and insert here as intInterval. For now, we just
leave it as 1 week
'*************************
.Interval = 1
'Once per week
.PatternStartDate = Me.txtStartDate
.PatternEndDate = Me.txtEndDate
End With
' Now that we're done with obJRecurPattern, set it to
nothing
Set objRecurPattern = Nothing
End If
.Save
.Close (olSave)
End With
End If
'Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
End If
Exit_cmdSchedule_Click:
' Release the Outlook object variables
' Note: I put this here so that it would run even if there's a error
Set objAppt = Nothing
Set objOutlook = Nothing
Exit Sub
ERR_cmdSchedule_Click:
MsgBox Err.Description
Resume Exit_cmdSchedule_Click
End Sub