473,382 Members | 1,086 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Unable to set focus on a combo box

Andrew Thackray
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
7 6075
NeoPa
32,556 Expert Mod 16PB
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
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
32,556 Expert Mod 16PB
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
Killer42
8,435 Expert 8TB
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
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
1,418 Expert 1GB
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
32,556 Expert Mod 16PB
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

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

Similar topics

0
by: Mike | last post by:
My original problem was solved by Bruce Dodds (Thanks!!) ORIGINAL PROBLEM I have developed an application for data enty for daily production in my factory. I have one combo box for shifts...
5
by: Paul | last post by:
I have read the posts on using Sendkeys to dropdown the list in a combo box. However, doesn't that require the combo box to have the focus? My situation is a little different. I have a text...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
0
by: Tim Bücker | last post by:
Hello. I have a mdi form with a toolbar including a combo box. Through this combo box some kind of shapes can be selected. These shapes reside on the mdi child forms and can be moved around with...
2
by: kenglish_hi | last post by:
hello, I have a form with a datagrid and combo box. When the form loads up, i want the focus to be on the combo box. however, whenever it loads up, the focus is always on the datagrid. in the...
1
by: Robert | last post by:
I borrowed one of the forms from the MS Access Solutions database and altered it to fit my needs. The form was the 'EditProducts' form where you select a category from a combo which then populates...
0
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hi Everyone, I have an issue thats bugging me some. I have a search form that I created to search for clients in the database from the Client form. User selects the client from a list and the...
1
by: Harry2007 | last post by:
Currently, my Access 2003 form only has 3 combo boxes with data sourced from different tables, a command button, a subform and 2 textboxes. Funny thing happened when I press the Enter key on the...
7
by: Orv | last post by:
I have a "Yes/No" combo box (set to required) and I want the focus to shift to differnet controls (on the same form) based on the selection of "Yes" or "No". Would this have to be placed on the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.