Need Guidance on Form Event

  • Thread starter Thread starter Michael Hyatt
  • Start date Start date
M

Michael Hyatt

Here's the scenario. The user has chosen to forward a message. The message
window is now open on the screen with the cursor positioned in the To field.
When the user has entered the name of the recipient and tabs out of the
field, I want to trap the event and insert the name of the recipient in the
body of the e-mail. I understand how to set the .body or .HTMLBody property.
However, I don't know how to attach the code to field's exit event. I can't
seem to find one! Is there such a thing?

What is the best way to approach this? Thanks.
 
I have gotten this far with the VBScript:

Sub Item_PropertyChange(ByVal Name)

If Name = "To" Then
StrTo = Item.To
iLength = Len(strTo)
iStart = InStr(1, strTo, ", ", vbTextCompare)

' This parses the To field value and extracts the first name.
If iStart = 0 Then ' In standard format of
FirstName LastName
iSpace = InStr(1, strTo, " ", vbTextCompare)
strFirstName = Left(strTo, iSpace - 1)
Else ' In reverse
format of LastName, FirstName
strFirstName = Mid(strTo, iStart + 2, iLength - iStart)
End If

' This inserts the first name, in bold, at the beginning of the
message.
strFirstName = "<Strong>" & strFirstName & "," & "</Strong>"
Item.htmlbody = strFirstName & Item.HTMLBody

End If

End Sub

This Subroutine fires after the user enters the name of the recipient and
then presses the Tab key. However, the cursor does not move to the next
field. I have tried to SetFocus to the CC field, but I cannot figure out how
to do this. SendKeys evidently doesn't work with VBScript. How can I move
the cursor to the next field?

Thanks.
 
Unfortunately, you can't set the cursor to any of those controls. Why do you
need to move the cursor there?

If all you want to do is insert the To property into the body, the best spot
for that is in the Item_Send event.
 
Hi Michael,

not tested but I think there is a way with some API Code: you would need
the Windowhandle of the To-Field etc. Then you should can check in a
Timer-Event if the Inspector still has the Focus (GetForeGroundWindow),
the Position of the Fields you are interested in (GetWindowRect) and the
current Position of the Cursor (GetCursorPos). Then compare the Cursor
Position with e.g. the Position of the To-Field.

It is a bit more of work - maybe to expensive.
 
Back
Top