By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

To Zoom with SendKeys, Shift F2, use DoEvents

Expert 100+
P: 446
Hi
I have often wanted to allow users to double-click on a control to open the Zoom window, instead of having to revert to the Shift +F2 keyboard method.

The command SendKeys "+{F2}" works for the On_Click event but not for Double_Click. You can open a message box but not the Zoom window!

However, I have found that by putting a DoEvents after the SendKeys, it works reliably.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Narrative_DblClick(Cancel As Integer)
  2. 'MsgBox "Double Click detected"
  3. SendKeys "+{F2}"
  4. DoEvents
  5. End Sub
This has bugged me for years so I was happy to find a fix.

Incidentally, I'm finding I need to put DoEvents in previously reliable code, after functions or calling procedures, to try and keep things synchronized. Whether this is because computers are faster or later versions of Access try multi-tasking, I don't know.

S7
Mar 19 '08 #1
Share this Question
Share on Google+
5 Replies


missinglinq
Expert 2.5K+
P: 3,532
You should never use SendKeys unless nothing else is available, which is not the case here!
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_DblClick()
  2.   DoCmd.RunCommand acCmdZoomBox
  3. End Sub
I have no idea on your DoEvents problem; never experienced it or read about it anywhere else. Perehaps your explanation is correct. What type of procedures are involved?

Linq ;0)>
Mar 19 '08 #2

FishVal
Expert 2.5K+
P: 2,653
DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.
Quite straightforward I guess. The question is why it worked previously.

Regards,
Fish.
Mar 19 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
Of course, using Why and SendKeys in the same sentence has always been a pretty futile exercise! There's never really been any rhyme or reason as to what they do or don't do!

Linq ;0)>
Mar 19 '08 #4

Expert 100+
P: 446
You should never use SendKeys unless nothing else is available, which is not the case here!
Expand|Select|Wrap|Line Numbers
  1. Private Sub YourTextBox_DblClick()
  2. DoCmd.RunCommand acCmdZoomBox
  3. End Sub
I have no idea on your DoEvents problem; never experienced it or read about it anywhere else. Perehaps your explanation is correct. What type of procedures are involved?

Linq ;0)>
Thanks for the comments guys! I thought that might get a response.

Thanks for the tip about acCmdZoomBox Linq. I failed to find that one! I agree totally about not using SendKeys and if this tests successfully, will swap at the next opportunity.

I haven't seen the Help topic refered to by Fish but originally used DoEvents to get other command buttons to respond while continuously looping to read data off COM1.

Since migrating a '97 project to 2003, one subform in particular showed #Error after a 'stock picking operation' when previously all was OK under '97. The system does things like;- find next next Invoice number; reduce quantity remaining on Batch, add quantity & BatchID to picked material; calculate and display profit. Nothing really difficult but requires steps to be performed in an orderly fashion. The text box for 'profit' showed #Error (which was disconcerting to the user!) although correct figures displayed on re-opening the form. Tried Refresh, Recalc, even Requery but found that DoEvents between the procedures worked. End of!

S7
Mar 19 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
DoEvents is always a good thing to try when you have muliple things running where some things may take a bit of time to complete. I've had to use it where a single button was used to print out multiple reports.

Still don't have a clue why you have to use it now when you didn't in ACC97. Never worked in 97. In every version since 2000 operations are asynchronous, but maybe that wasn't true in 97.

Linq ;0)>
Mar 19 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.