Application.Wait ?

J

John Strung

I have some code that opens Outlook and addresses and e-mail from a button
in Access. All was well and good until we got faster computers and this has
caused a problem with SendKeys firing too soon (yes I know not to use
SendKeys if it can be avoided). I am looking to introduce a short delay
before the SendKeys instructions and I have seen suggested elsewhere on the
web to use:

Application.Wait (Now + TimeValue("0:00:02"))

This was suggested in the context of launching Outlook from Excel, rather
than Acces.

However, when I try this, the code won't compile and I get a "method or data
member not found" error. Is this instruction limited to Excel? Is there a
workaround?
 
E

Eric Legault [MVP - Outlook]

Yup, it looks like the Wait call is exclusive to Excel's Application object.

You could try using a class based timer, like this one:

vbAccelerator - High Resolution Multimedia Timer:
http://www.vbaccelerator.com/home/VB/Code/Libraries/HiResTimer/article.asp

I believe there are also some samples and libraries at vbAccelerator that
could show you how to use Win32API calls for manipulating any displayed
Window, including clicking buttons; this may be better than using SendKeys.
 
J

John Strung

Thanks, Eric.

I have now tried adding in the Excel Object Library under References, and
then added the line:

Excel.Application.Wait (Now + TimeValue("0:00:02"))

to my code and that seems to work.
 
M

Michael Bauer

Wow, starting Excel for waiting a few milliseconds - that´s great. I
suppose the starting process causes enough delay so you don´t need to
call the Wait method additionally :)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 
J

John Strung

Michael Bauer said:
Wow, starting Excel for waiting a few milliseconds - that´s great. I
suppose the starting process causes enough delay so you don´t need to
call the Wait method additionally :)

Yikes! I didn't realize that that command actual started Excel. I assumed it
just allowed access to the Excel library. I see from Task Manager that you
are right, it in fact starts Excel.

Unforturnately, that didn't solve the problem I was trying to solve. I had
assumed the problem was SendKeys firing too soon, but inserting the delay
made it apparent to me that that wasn't the problem.

The problem I am having is that the code is supposed to address the message,
add some information (file number, etc.) to the body of the message, add a
couple of lines, then add the signature at the bottom. The SendKeys
instructions are just to the move the cursor so that the signature gets
added at the bottom of the message and not at the top, the return the cursor
to the proper part of the message for typing.

The problem I am having is intermittent which makes it difficult to track
down. What happens, every once in a while, is that the script runs, but the
signature does not insert. In fact, when I then try to insert the signature
manually, it won't insert, and the message won't send. I have to save the
message, then re-open it from the Drafts folder, after which it allows me to
insert the signature and send the message. It is as if something is locking
the message.

To make it worse, the problem is intermittent, which make is difficult to
debug.

If you have any thoughts, they are welcome.

Thanks
 
M

Michael Bauer

John,

as you pointed out earlier yourself: Don´t waste your time with
SendKeys.

For cursor positions I´d recommend the Redemption from www.dimastr.com.
Another way´d be to use Word as you editor.
 
J

John Strung

Michael said:
For cursor positions I´d recommend the Redemption from www.dimastr.com.
Another way´d be to use Word as you editor.

Thanks, Michael, I do in fact have Redemption and am using it to
circumvent the Outlook security block, but don't see how to use it to
set the cursor position in the message field. Can you point me in the
right direction?
 
J

John Strung

Michael, I am struggling with Safe Inspector.

If I insert codes as per the example at the link you cited:

Dim sInspector
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
sInspector.SelText = "this text had just been inserted"
MsgBox "You have selected: " & sInspector.SelText


the example code seems to work. However if I try to get the cursor position
using this code:

Dim sInspector
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
MsgBox "Cursor position: " & CStr(sInspector.CaretPosY)


I get an error message "run time error 438 - Object doesn't support this
property or method"
 
M

Michael Bauer

That´s correct. The page tells you that CaretPosY is a method of the
PlainTextEditor e.g. :)
 
J

John Strung

For the benefit of any one else reading this, the srcript I used was as
follows:

x = 6
If IsNull(Me![Claimno]) = True Then x = x - 1
If IsNull(Me![DateLoss]) = True Then x = x - 1
Dim sInspector
Dim plaintexteditor
Set sInspector = CreateObject("Redemption.SafeInspector")
sInspector.Item = Outlook.ActiveInspector
Set plaintexteditor = sInspector.plaintexteditor
plaintexteditor.CaretPosY = x
 
M

Michael Bauer

Thanks, John. Please don´t forget to clean up sInspector.Item and
sInspector in the end.
 

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