What can prevent focus being set?

Matt Greatorex

Registered User.
Local time
Today, 09:53
Joined
Jun 22, 2005
Messages
1,019
I have a field on a form that displays a list of people. In most cases, one record = one person, but in a few one record = one team of two or more people.

Selecting a record causes the rest of the form to be populated. This works fine.

What I've added is as follows:
1) User enters a name and hits <Enter>
2) If the name relates directly to a record for one person, code acts as before.
3) If the name is part of a team, a second field is made visible, enabled, and set to contain only those records that might relate to the entered name. This works fine.

If the second case is true, however, I want focus to shift from the first field to the second. I'm trying to use
Code:
[Forms]![frm_NBDash-IA]![cbo_Possibilities].SetFocus
but I get a message saying

'Microsoft Access can't move the focus to the control cbo_Possibilities'

I've checked the properties of both fields and they appear to be identical. What else can prevent SetFocus from working? :confused:
 
Are you putting the SetFocus code after or before the code to make the combo box visible? It has to be visible before the focus can be set.
 
boblarson said:
Are you putting the SetFocus code after or before the code to make the combo box visible? It has to be visible before the focus can be set.

Thanks for the response.

Unfortunately, it's after. The full sequence is:
Code:
[Forms]![frm_nbdash - ia]![cbo_Possibilities].RowSource = str_Source
[Forms]![frm_nbdash - ia]![cbo_Possibilities].Requery
[Forms]![frm_nbdash - ia]![cbo_Possibilities].Visible = True
[Forms]![frm_nbdash - ia]![cbo_Possibilities].Enabled = True
[Forms]![frm_nbdash - ia]![cbo_Possibilities].SetFocus
 
Matt:

Can you post a stripped down version of your database here so I can try looking at it directly?
 
Stupid question: How do I do that (not the stripped down bit, the posting)?
 
Go into Advanced posting mode (see the Go Advanced button below the Quick Reply window) and then when you've typed your message, scroll down the page and you should see MANAGE Attachments.
 
Try setting focus to the Form first and then the combo box, ie two separate set focus statements
 
Thanks to both.

Setting focus to the form, then to the control didn't help, unfortunately.

As is their wont, the bosses here have now shifted my priorities and I'll be working on something else for a while at least. As soon as i can get back to this issue, i'll post the stripped down mdb and, hopefully, someone can spot which obvious mistake I'm making.
 
Check the Locked status also.
 
i know you are on something else - is it possible that youu have an oncurrent event say, that is moving the focus again AFTER your code executes.

try a breakpoint in that sequence relating to the combobox, and see where the code flows.
 
Okay, it’s back to this problem - until the powers that be decide otherwise, that is.

Hopefully, the posted ‘cut down and doctored’ version of the db will give you the gist of the problem(s).

In summary, when everything works:

1) Select a record from the topmost, left list.
2) The rest of the fields get populated, or not, depending on the available data.

Where the problem occurs:

1) Type a surname into the same field.
2) If you enter ‘Smith’ and hit <Enter>, the process works.
3) If you enter ‘Jones’ or ‘Davies’, you get the usual ‘Not In List’ behaviour.

What I would like to happen:
1) Type in ‘Smith’ – one matching record is found, everything works as it does now.
2) Type in ‘Jones’ – One record is found containing the word ‘Jones’. The field gets populated with the details. Everything else continues as now.
3) Type in ‘Davies’ – Multiple records are found. A second field is made visible, populated with just those records containing the word ‘Davies’ and focus is shifted to this new field. Everything else continues as now.

Any help gratefully appreciated and if anyone has any questions, please don't hesitate.
 

Attachments

Users who are viewing this thread

Back
Top Bottom