This VBA function sporadically fails with a Notes automation error "Run-Time Error '7' Out of Memory". Naturally, when I try to manually reproduce it, everything runs fine.
Function ToGMT(ByVal X As Date) As Date
Static NtSession As NotesSession
If NtSession Is Nothing Then
Set NtSession = New NotesSession
NtSession.Initialize
End If
(do stuff)
End function
To put this in context, this VBA function is being called by an Access query, 3-4 times per record, with 20,000 records. For performance reasons, the NotesSession has been made static. Any ideas why it is sporadically giving an out-of-memory error?
(Also, I'm initiating the NotesSession just so I can convert a datetime to GMT using Lotus's rules. If you know a better way, I'm listening).
Edit
Per Mr. Ross's question, I isolated (or thought I did) the query and it's supporting function. Before I tried your suggestion, I added some arguments first to determine which row & field it crashed on. I ran it a few times and it crashed on the first field of the 开发者_JAVA技巧first row.
Then presto! Everything ran fine. So I tried to backtrack to see what I did. Couldn't find anything. I even went back to the original query where it was failing consistently and found that everything ran fine even though nothing had changed (or so I think).
So, I couldn't try your suggestion, but I still learned something. This is really annoying me. Could this function be conflicting with some other Notes process?
(1 other thing. It can't be a hardware/memory issue. This machine is a dual core with 2gb RAM.)
Edit #2
This is really taking up too much of my time. I've decided to just hardcode the dates. Mr. Ross, your link looks like a solid, full-featured function, but I haven't the time anymore to check the logic. Here's what I went with instead: (it works better than I thought for my purposes. I was expecting more discrepancies)
Function ToGMT(ByVal X As Date) As Date
'Ugly? Yes. A cheap hack? Yes.
'But this method is fast and verifiable. So let's go with it.
'Of course, if you're reading this in the year 2016, well,
'you should be able to figure out what to do.
If X >= #4/2/2006 1:00:00 AM# And X <= #10/29/2006 3:00:00 AM# Or _
X >= #3/11/2007 1:00:00 AM# And X <= #11/4/2007 3:00:00 AM# Or _
X >= #3/9/2008 1:00:00 AM# And X <= #11/2/2008 3:00:00 AM# Or _
X >= #3/8/2009 1:00:00 AM# And X <= #11/1/2009 3:00:00 AM# Or _
X >= #3/14/2010 1:00:00 AM# And X <= #11/7/2010 3:00:00 AM# Or _
X >= #3/13/2011 1:00:00 AM# And X <= #11/6/2011 3:00:00 AM# Or _
X >= #3/11/2012 1:00:00 AM# And X <= #11/4/2012 3:00:00 AM# Or _
X >= #3/10/2013 1:00:00 AM# And X <= #11/3/2013 3:00:00 AM# Or _
X >= #3/9/2014 1:00:00 AM# And X <= #11/2/2014 3:00:00 AM# Or _
X >= #3/8/2015 1:00:00 AM# And X <= #11/1/2015 3:00:00 AM# Then
ToGMT = DateAdd("h", -1, X)
Else
ToGMT = X
End If
End Function
What happens when you change it NtSession from being a static to being setup on each call to the function and then set to nothing at the end of the function?
I know it will hurt performance but give it a shot and see what happens and post back
EDIT:
Your comment about converting to GMT got me thinking, would this funciton be of any good?
http://www.vbaexpress.com/kb/getarticle.php?kb_id=813
精彩评论