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

Unable to set focus on a combo box

Andrew Thackray
P: 76
Has anyone seen this problem before ?

I have this code that displays a hidden combo box and sets the focus to it

cmbActivityType.Visible = True
cmbActivityType.SetFocus


When the code executes it breaks with the message "Unable to move focus to cmbActivityType.

However if I simply continue executing the code it executes with no problems.

It's almost as if the setfocus is executing before the visible command has finished.?

I have tried putting a 1 second delay betweeen the two code lines but this does'nt work either.

Any Idaes as to what is causing this ??
Oct 26 '06 #1
Share this Question
Share on Google+
7 Replies


NeoPa
Expert Mod 15k+
P: 31,419
No idea really.
Try putting a Debug line in between the two lines :-
Expand|Select|Wrap|Line Numbers
  1. cmbActivityType.Visible = True
  2. Debug.Print cmbActivityType.Visible
  3. cmbActivityType.SetFocus
Oct 26 '06 #2

Andrew Thackray
P: 76
No idea really.
Try putting a Debug line in between the two lines :-
Expand|Select|Wrap|Line Numbers
  1. cmbActivityType.Visible = True
  2. Debug.Print cmbActivityType.Visible
  3. cmbActivityType.SetFocus
weird !!

I tried that & put a stop after the setfocus command

when I do this the code executes fine & the debug shows combo box as visible.

If I remove the debug line the problem comes back !!

if I insert the debug & don't stop the code it works fine

I'll leave the debug in the code to get it working but I really would like to know what is going on
Oct 26 '06 #3

NeoPa
Expert Mod 15k+
P: 31,419
lol

Now, let's get this straight - that was supposed to provide information - not fix the problem :-D
I'm sorry, but I understand that no better than you.
Oct 26 '06 #4

Expert 5K+
P: 8,434
lol

Now, let's get this straight - that was supposed to provide information - not fix the problem :-D
I'm sorry, but I understand that no better than you.
You might try doing a refresh of the form or the control before the SetFocus, just to see what happens. Perhaps a DoEvents, as well. Probably shouldn’t be necessary, but if it works then at least it will look a little less “kludgy” than the Debug print. And is probably less likely to be removed later by a conscientious programmer.
Oct 27 '06 #5

Andrew Thackray
P: 76
This has me baffled. The problem appeared after the code had been running for a while. I had not made any changes to the code affected when the problem appeared., I now am also getting errors when updating records whth an error "Access has stooped the process bgecause two users are simultaneously trying to update the date" - ie the proverbiial deadly embrace. However I am the only user and the only update on the record appears some tens of lines earlier. This also suddenly appeared after the code was wotking fime.

However the diffreence is that my computer has been upgraded to a very fast 64 bit dual processor machine. If I move the code to my laptop which is much less powerful it suddenly starts working flawlessly.

I suspect that what is happening is that Access is passing some operations off to separate threads during execution. In a single processor machine these can only be executed sequentially and in the order launched, no matter how fast the machine is. However with a dual processor it is possible that the threads are being executed in parallel & therefore it is possibl;e that a thread launched after a previous thread can finish first. This could explain why putting a debug print in would work as it interrupts the current forground thread long enough for the earlier thread to complete.

This is the only explanation I can think of as the code running on my two machines is identical.
Oct 27 '06 #6

PEB
Expert 100+
P: 1,418
PEB
Hi ,

Really I don't think that Access should have different beheviour on different machines...

It seems to be the code that you use...

Can you provide us information about on which event procedure is stored your code and what are you doing with the code?

This thing arrives when you use before update and after update event procedures...

:)
Oct 27 '06 #7

NeoPa
Expert Mod 15k+
P: 31,419
You might try doing a refresh of the form or the control before the SetFocus, just to see what happens. Perhaps a DoEvents, as well. Probably shouldn’t be necessary, but if it works then at least it will look a little less “kludgy” than the Debug print. And is probably less likely to be removed later by a conscientious programmer.
I was searching around in my code for the
Expand|Select|Wrap|Line Numbers
  1. Call DoEvents()
function as a suggestion but couldn't find it anywhere.
(obviously I'm too old to remeber it properly without help :-( )

Well done to Killer42 for mentioning that.
Oct 27 '06 #8

Post your reply

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