Hi
montanan,
The easiest way to use the script you've written is uncompiled... on a machine with Macro Scheduler installed... just assign it a Hot Key and when you're in that SugarCRM field, tap the Hot Key - sounds like that's working OK for you.
Since you are trying to get it to work compiled, I assume you want to have other users (that don't have Macro Scheduler on their machines) use it. If so, how are you triggering the macro on those other machines? Without Macro Scheduler installed, you can't just set a Hot Key.
One way is to create a desktop shortcut icon, point it to the compiled exe on their PC and set a Hot Key in the properties of that icon... just make sure you use some Hot Key combination that no other application is likely to use or you may have problems.
When the user hits that Hot Key and your exe starts up, yes... focus will move from your SugarCRM window to your exe and so your problem becomes, how do you get focus back to where you want it so that when it pastes, the text will go there?
Question - is this macro you wrote *only* to be used for SugarCRM? If so, then yes, you could add a SetFocus line to set the focus back on SugarCRM.
However, if your macro is meant to be a general purpose date stamper to stamp into a variety of apps, then that won't work well... but here's an alternative. Have your macro send ALT TAB just before it sends the date text. That will tell Windows to "switch focus back" to the app that previously had focus... before your exe took focus. That way you will be able to use it to stamp into notepad, Word, SugarCRM, etc.
Be sure to use some Wait> statements in between the keys you're sending to give windows time to react. You can start at a second or two and then keep paring it down to make it faster... while testing to make sure its still reliable on the machines you are running on.
Let us know how you make out...
By the way, if you are willing to have your exe running all the time on the target machine... watching for a particular combination of keys to be pressed, you could also check out the OnEvent> command in the Help File... specifically KeyDown, i.e.:
Help File wrote:OnEvent>KEY_DOWN,VK32,3,KeyPress
The above line waits for ALT+Space to be pressed and when it is, it sends execution to the "Keypress" subroutine... you could have most of your code in there to accomplish your datestamp... again see the example Marcus has for OnEvent> in the Help File.