UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Send Email Place Cursor In To, Access 2016    
 
   
tobyhanna
post Feb 13 2018, 09:10 AM
Post#1



Posts: 131
Joined: 7-February 06



Hello,

I have a SendMail function that sets the To, CC, Subject & Body and then opens the email for the user to update prior to sending. The user want the cursor in the To field, is it possible to move it from the Body to the To? I tried using SendKeys, the CTRL+END and END works by moving the cursor to the end of the body but what I want to replicate is ALT+TAB three times. SendKeys ALT+TAB has the effect of changing windows three times, not moving the cursor in the email. Is there another way to move the cursor between fields in the email once it's displayed?

Thank you,
Liesl

CODE
Dim oOutlook As Object
Dim oMail As Object

Dim olMailItem As Integer
Dim olFormatRichText As Integer

olMailItem = 0
olFormatRichText = 3

Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(olMailItem)

With oMail
    .BodyFormat = olFormatRichText
    .To = sTo
    .CC = sCC
    .Subject = sSubject
    .Body = sMsg
    .Display '- moved to top because of 2016 bug
    'SendKeys "^+{END}", True
    'SendKeys "{END}", True
    SendKeys "%+{TAB}", True
    SendKeys "%+{TAB}", True
    SendKeys "%+{TAB}", True
End With
Go to the top of the page
 
DanielPineault
post Feb 13 2018, 10:09 AM
Post#2


UtterAccess VIP
Posts: 5,951
Joined: 30-June 11



There is no easy way to do this (to my knowledge). (Stay away from SendKeys!)

You could get into using a tool to get the control's ID, then use APIs to get its handle and move the focus there, but you're getting into some advanced coding for something the user can easily do with a single click of there mouse.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
tobyhanna
post Feb 13 2018, 11:47 AM
Post#3



Posts: 131
Joined: 7-February 06



Thank you Daniel. The trouble is the user sees the TO default if the TO is left blank. If the TO has a value, the BODY defaults. Either way I suppose they will have to tab forward or back 50% of the time.

Thanks again for your response,
Liesl
Go to the top of the page
 
theDBguy
post Feb 13 2018, 11:51 AM
Post#4


Access Wiki and Forums Moderator
Posts: 72,436
Joined: 19-June 07
From: SunnySandyEggo


Hi Liesl,

Not sure why you were using Alt+Tab. Did you mean to use Shift+Tab?

Just curious...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
tobyhanna
post Feb 13 2018, 12:47 PM
Post#5



Posts: 131
Joined: 7-February 06



Hi DBguy,

Thank you! Yes, I mean Shift, of course Alt changed screens (oh my). I updated the SendKeys below and all is well. I added an if to check if the TO was empty, otherwise it would tab back from there three times.

CODE
If sTo <> "" Then
    SendKeys "+{TAB}", True
    SendKeys "+{TAB}", True
    SendKeys "+{TAB}", True
End If


Thanks for you keen eye,
Liesl
Go to the top of the page
 
theDBguy
post Feb 13 2018, 12:56 PM
Post#6


Access Wiki and Forums Moderator
Posts: 72,436
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Glad to hear you got it squared away. Cheers!

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
tobyhanna
post Feb 19 2018, 02:09 PM
Post#7



Posts: 131
Joined: 7-February 06



Well, Daniel's warning about SendKeys was spot on. For my computer, it was three tabs back. For the user's computer, it was a different amount of back tabs.

So, to solve this issue, before setting the .TO value, I have a test and if true, it set sTo = "" so that forces the .TO field to have the focus when the email displays.

Thanks again for all you help!
Liesl

CODE
Dim oOutlook As Object
Dim oMail As Object

Dim olMailItem As Integer
Dim olFormatRichText As Integer

olMailItem = 0
olFormatRichText = 3

Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(olMailItem)

With oMail
    .BodyFormat = olFormatRichText
    If True then sTo = ""
    .To = sTo
    .CC = sCC
    .Subject = sSubject
    .Body = sMsg
    .Display
End With
Go to the top of the page
 
theDBguy
post Feb 19 2018, 02:49 PM
Post#8


Access Wiki and Forums Moderator
Posts: 72,436
Joined: 19-June 07
From: SunnySandyEggo


Nice going. Cheers!

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    22nd June 2018 - 02:05 PM