Help! "Out of Memory" errors with Appointments created from Acces

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
 
D

Dirk Goldgar

Chris O''''Neill said:
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


I don't see where you ever quit the Outlook application object you create.
I've never actually tried to automate Outlook, but shouldn't there be a
line,

objOutlook.Quit

before you exit the procedure?
 
C

Chris O''''Neill

Dirk Goldgar said:
I don't see where you ever quit the Outlook application object you create.
I've never actually tried to automate Outlook, but shouldn't there be a
line,

objOutlook.Quit

before you exit the procedure?

Thank you, Dirk, for the reply. No, there isn't an "objOutlook.Quit" line
in the code. I went back and checked the KB article, and there's no "quit"
line in that code either. (I copied and pasted that code, so thought I'd
better check in case I missed a line.)

I'll add that line and see if it helps. What perplexes me, though, is that
appointments I create in Outlook open without a problem, but appointments I
create in Access (using this code) and send to Outlook trigger the error.
Why????

Regards, Chris
 
P

Pete D.

You probally need to take this to outlook newsgroup but first verify you are
placing the right data type in all the fields for outlook. You may be
stuffing an invalid integer or something into a date field and so on. Also
use "Set objOutlook = Nothing" at the end of your code before it exits.
 
C

Chris O''''Neill

Thanks, Pete, for the reply. I do have "Set objOutlook = Nothing" at the end
of the code before the subroutine exits. It looks like the problem was not
having the "objOutlook.Quit" line in the code because I changed that and it
now *seems* to be working okay. All appointments (Outlook native and Access
created) are opening without error messages. Btw, I find it interesting that
the Microsoft article (ID #209963) didn't have that line in it!

Thanks, again, to everyone who replied. MUCH appreciated!

Regards, Chris
 
S

Stuart McCall

Chris O''''Neill said:
Thanks, Pete, for the reply. I do have "Set objOutlook = Nothing" at the
end
of the code before the subroutine exits. It looks like the problem was
not
having the "objOutlook.Quit" line in the code because I changed that and
it
now *seems* to be working okay. All appointments (Outlook native and
Access
created) are opening without error messages. Btw, I find it interesting
that
the Microsoft article (ID #209963) didn't have that line in it!

Thanks, again, to everyone who replied. MUCH appreciated!

Regards, Chris

Because you weren't explicitly closing Excel, instances were building up in
ram, till you got the out of memory error. Setting your instance variable to
Nothing doesn't close Excel. objOutlook.Quit does.

(just thought you might like to understand why it failed)
 
C

Chris O''''Neill

Thank you, Stuart, for increasing my knowledge. That does makes sense. But
if that were the case, wouldn't I have gotten the error message when trying
to open any message??? My problem was that the error message triggered only
when trying to open appointments I created in Access and sent to Outlook.
Appointments created directly in Outlook still worked fine.

Regards, Chris
 
S

Stuart McCall

Chris O''''Neill said:
Thank you, Stuart, for increasing my knowledge. That does makes sense.
But
if that were the case, wouldn't I have gotten the error message when
trying
to open any message??? My problem was that the error message triggered
only
when trying to open appointments I created in Access and sent to Outlook.
Appointments created directly in Outlook still worked fine.

<shrug> Sorry, I've never run across that particular problem. So this'll
have to be a guess. When you created your message and sent it to Outlook
(got the app name right this time!), did you objOutlook.Quit afterwards?
 
D

dch3

Try taking out the reoccurrance. That might be were the issue is. If it is,
you'll need to rely on the Outlook group to hammer out what the specific
problem is.
 
D

dch3

Oh and FYI - Do you have a reference set to the Outlook library? Fess up -
you're using outlook constants. While that won't fix the problem, if you use
the code on any other machine, you'll have to set the same reference on each
machine for the code to work - (just if you weren't aware of that caveat).

Chris O''''Neill said:
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
 
D

dch3

Pardon me while I just ramble on...

If you don't have an reference set, the issue might be the line...

..RecurrenceType = olRecursWeekly

Access won't know the value of olRecursWeekly. Since you don't have Option
Explicit in the module (you don't have objOutlook and objAppt Dim'd), you
won't know that olRecursWeekly is more or less unknown. If the reference is
set, Access will know the value of it and not throw an error when you
compile. But if the reference is NOT set, Access will through an error
indicating that its not declared.

Chris O''''Neill said:
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
 
D

dch3

Ok, so I just missed the lines that you have them Dim'd (I'm used to grouping
my Dim's all together)...I'm just going to go away, shut up and hide under a
rock before I get spammed....

Chris O''''Neill said:
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
 
C

Chris O''''Neill

Okay, I confess... yes, I'm referenced to the Outlook 10.0 Object Library,
and I know that means any machine running the application needs that
reference. Is there a way to do it with a generic library that any machine
would have?

Regards, Chris


dch3 said:
Oh and FYI - Do you have a reference set to the Outlook library? Fess up -
you're using outlook constants. While that won't fix the problem, if you use
the code on any other machine, you'll have to set the same reference on each
machine for the code to work - (just if you weren't aware of that caveat).

Chris O''''Neill said:
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
 
C

Chris O''''Neill

No need to hide under a rock. I really do appreciate your suggestions as it
helps me learn.

Normally, I place all Dim's at the beginning of a subroutine, and I've since
done that here too, but at that point I had the Dim's inside the IF/Then
statements so that they wouldn't occur unless the appointment was going to be
created.

I think the problem was not having the objOutlook.quit statement in the
code, as the problem disappeared shortly after I inserted it. There also was
a problem with the recurrance code where it was assigning a 1 week recurrance
on events with the same date for start and end. That might have been
confusing Outlook.

At any rate, the problem *has* been resolved and the subroutine is
functioning beautfilly. Thanks, again, for your suggestions and tips. (That
goes for *everyone* who replied!)

Regards, Chris

dch3 said:
Ok, so I just missed the lines that you have them Dim'd (I'm used to grouping
my Dim's all together)...I'm just going to go away, shut up and hide under a
rock before I get spammed....

Chris O''''Neill said:
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
 
D

dch3

I find it odd that objOutlook.quit would be the problem. I've been creating
Outlook Appointments and MailItems from both Excel and Access for a good long
time now - 3 years maybe - and have never actually used it or encountered any
problems. I assumed that SETting the object variable to NOTHING did the job.

Oh well live and learn...now young grasshopper, can you catch a fly with
chopsticks with your eyes blindfolded as you stand on one leg singing the
poetry of Emily Dickenson to the tune of Gilligan's Island as you balance a
pot of flowers on your head? Only then will the world take you seriously.

Chris O''''Neill said:
No need to hide under a rock. I really do appreciate your suggestions as it
helps me learn.

Normally, I place all Dim's at the beginning of a subroutine, and I've since
done that here too, but at that point I had the Dim's inside the IF/Then
statements so that they wouldn't occur unless the appointment was going to be
created.

I think the problem was not having the objOutlook.quit statement in the
code, as the problem disappeared shortly after I inserted it. There also was
a problem with the recurrance code where it was assigning a 1 week recurrance
on events with the same date for start and end. That might have been
confusing Outlook.

At any rate, the problem *has* been resolved and the subroutine is
functioning beautfilly. Thanks, again, for your suggestions and tips. (That
goes for *everyone* who replied!)

Regards, Chris

dch3 said:
Ok, so I just missed the lines that you have them Dim'd (I'm used to grouping
my Dim's all together)...I'm just going to go away, shut up and hide under a
rock before I get spammed....

Chris O''''Neill said:
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
 
C

Chris O''''Neill

dch3 said:
I find it odd that objOutlook.quit would be the problem. I've been creating
Outlook Appointments and MailItems from both Excel and Access for a good long
time now - 3 years maybe - and have never actually used it or encountered any
problems. I assumed that SETting the object variable to NOTHING did the job.

Well, I'm still a bit doubful that it was that, too, because the error only
triggered with appointments I created in Access. But, not having any other
explanation, I'll settle for that one. ;)
Oh well live and learn...now young grasshopper, can you catch a fly with
chopsticks with your eyes blindfolded as you stand on one leg singing the
poetry of Emily Dickenson to the tune of Gilligan's Island as you balance a
pot of flowers on your head? Only then will the world take you seriously.

Uhhhh.... No, I don't think I can do that. But I'll sure stand here and
watch while YOU do it! :D

Btw, do you happen to have any sample Access code for opening Outlook to a
specific contact item? I have the code finished to create an item if one
doesn't exist, but I really want to do this:

If contact item exists then
load contact item and let user edit it if they want
Else
create a new contact item ' <--- I have this code done
End If

I'm told that I need to store the contact item ID and parent store ID and
use that in the Namespace,GetItemfromID method. So far, I have this code in
my "create a contact item" routine to grab the entry ID and parent store ID:

Me.OutlookEntryID = .EntryID
Me.OutlookParentStoreID = .Parent.StoreID

When this code runs, I get nothing ("") in Me.OutlookEntryID and a *really*
long
number in Me.OutlookParentStoreID. So, I *think* I've got the parent store
ID but it
looks like I'm not getting the contact item's entry ID. Am I doing
something wrong?

Also, once I've got these ID's (and have stored them in the contact's record
in my Access database, how do I use Namespace,GetItemfromID to call up the
contact record?

Any code snippets you could share with me would be *really* helpful!

Thanks, in advance, from a not-so-young grasshopper...

Regards, Chris
 
S

Stuart McCall

Chris O''''Neill said:
No need to hide under a rock. I really do appreciate your suggestions as
it
helps me learn.

Normally, I place all Dim's at the beginning of a subroutine, and I've
since
done that here too, but at that point I had the Dim's inside the IF/Then
statements so that they wouldn't occur unless the appointment was going to
be
created.
<snip>

You can't have conditional Dim statements in any flavour of VB or VBA. Even
though you place them inside If Then blocks, the compiler reads them and
allocates memory for the variables in it's first pass through the code, then
it compiles the code in another pass. So just where you place them inside a
procedure is irrelevant. That's why most developers place them at the start
of the procedure. That way they're conveniently grouped together, and you
might as well anyway (for the above reason).

HTH
 
P

Pete D.

Yea and I missed the = none
dch3 said:
Ok, so I just missed the lines that you have them Dim'd (I'm used to
grouping
my Dim's all together)...I'm just going to go away, shut up and hide under
a
rock before I get spammed....

Chris O''''Neill said:
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
 
C

Chris O''''Neill

Stuart McCall said:
You can't have conditional Dim statements in any flavour of VB or VBA. Even
though you place them inside If Then blocks, the compiler reads them and
allocates memory for the variables in it's first pass through the code, then
it compiles the code in another pass. So just where you place them inside a
procedure is irrelevant. That's why most developers place them at the start
of the procedure. That way they're conveniently grouped together, and you
might as well anyway (for the above reason).

Really? I didn't know that. Ya learn something new everyday! Thanks!

Regards, Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top