Form Event when switching between another windows program and Access (1 Viewer)

sxschech

Registered User.
Local time
Today, 13:41
Joined
Mar 2, 2010
Messages
792
I have a form where I would like to enable a button only when the clipboard contains a particular string/phrase. The purporse of the button is to paste data into a table and if the data isn't what is supposed to be pasted, don't want to inadvertently add it. When the form opens, if the phrase isn't in the clipboard, I set the button to enabled=false. Next I switch to the non-access program, in this example, Chrome browser. Copy some text, then switch back to Access. At this point, I tried the Form's GotFocus event as well as the Form's Click event and neither seemed to fire, so the code to test whether to enable is not run. Is there a different event or code needed to make this work?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:41
Joined
Aug 30, 2003
Messages
36,124
Untested but try the activate event. Not sure if it works with an external program.
 

sxschech

Registered User.
Local time
Today, 13:41
Joined
Mar 2, 2010
Messages
792
Tried your suggestion and it does not seem to work for external program. Activate works when switching between forms within access. I guess I'll need to figure out a different approach.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:41
Joined
Aug 30, 2003
Messages
36,124
Sorry, I should have tested; I was afraid it might not work with an external program. Offhand I can't think of what would. Hopefully someone else can.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:41
Joined
Sep 21, 2011
Messages
14,238
Could you use the Call Stack to see what events are used.?

Not something I have ever played with myself, but I seem to recall someone mentioning it a while back.?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:41
Joined
Aug 30, 2003
Messages
36,124
I'm not familiar with it either.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:41
Joined
May 21, 2018
Messages
8,525
FYI the form's focus event almost never fires because you do not see a lot of forms without any visible enabled controls.
If a form contains any visible, enabled controls, the GotFocus event for the form doesn't occur
 

sxschech

Registered User.
Local time
Today, 13:41
Joined
Mar 2, 2010
Messages
792
I think I found an alternative solution. Rather than enabling and disabling the button, I put the if statement in the on click event of the text box. If the button is clicked and the expected string isn't found, it pops up a messagebox saying to go get the data and then click the button.
 

sxschech

Registered User.
Local time
Today, 13:41
Joined
Mar 2, 2010
Messages
792
Not sure how using a timer would help for my application as I'm not having the data pasted into a textbox. The form only has a button on it, which runs code that parses the clipboard data into a recordset loop to append vbcrlf delimited text rows into a table. This saves me from the extra step of pasting what I copy. Appreciate your effort though and will save for future possibility.
 

Users who are viewing this thread

Top Bottom