Focus problem

  • Thread starter Thread starter Bob Hughes
  • Start date Start date
B

Bob Hughes

I have a form with a query as a record source. The form header has a text
box (EmployeeID) used as a criteria in the query.
When there is no value in EmployeeID I cannot force the focus to this text
box in the form header. I don't know where the focus is, but I can use the
mouse to set it.
The detail section has all the fields set enabled no, locked no.

How do I force the focus to the header?
Just another little thing to drive me crazy!

Bob
 
Hi Bob,

Firstly, you should be able to set the text boxes TabIndex to 0 (zero).
This should work in most circumstances.

If this doesn't work, something else in a VBA module might be changing the
focus programatically.
To force the text box to become focused, try the following VBA code in the
forms OnOpen event (or OnCurrent might be more suitable for you);

Private Sub Form_Open(Cancel As Integer)

Me!EmployeeID.SetFocus ' Programatically set the focus

End Sub

Note that i've assumed EmployeeID is the name of the control and not the
name of the underlying field of the forms record source.

Regards,

Wayne Phillips
http://www.everythingaccess.com/forums -> New Forum!
 
Thanks Wayne
Interesting! I was at first going to say the setfocus did not work but then
I noticed I had used
Me.EmployeeID.SetFocus
not
Me!EmployeeID.SetFocus
This was from a discussion I read that said the 2 were equal.

At any rate now when the form is first loaded I am able to set focus on the
text box.

I have a new followup problem. When someone enters a wrong number I present
a message box & then try to set focus back on the text box with
Me!EmployeeID.SetFocus
BUT no luck. It's as if I'm not pointing to the form header.

You mentioned "set the text boxes TabIndex to 0" Where/how do I do that?

Bob
 
Thanks Wayne
Interesting! I was at first going to say the setfocus did not work but then
I noticed I had used
Me.EmployeeID.SetFocus
not
Me!EmployeeID.SetFocus
This was from a discussion I read that said the 2 were equal.

They are not quite 'equal', Me!EmployeeID actually expands to
Me.Controls.Item("EmployeeID") when it is compiled, but I don't want to bore
you with that stuff here!
At any rate now when the form is first loaded I am able to set focus on the
text box.

I have a new followup problem. When someone enters a wrong number I present
a message box & then try to set focus back on the text box with
Me!EmployeeID.SetFocus
BUT no luck. It's as if I'm not pointing to the form header.

When you say 'someone enters a wrong number' do you mean in the EmployeeID
control? Or is it a control within the sub form you are talking about?
Also, are you actually using the MsgBox function or are you validating the
field using a Validation rule for the control?
You mentioned "set the text boxes TabIndex to 0" Where/how do I do that?

Open the form in design mode from within Access. Right click the EployeeID
control and select 'Properties' from the drop down menu.
In the properties window, find the 'Tab Index" property and set it to zero.

Wayne Phillips.
http://www.everythingaccess.com/forums
 
Wayne,
I do have Tab Index set to 0. I've always set that from the view, tab
order window.

Sorry I did not explain my problem clearly.

The form is intended to show the status of an order to the user, but if
he does not have an order in progress I just tell her so & then attempt
to return to pick up a new user ID. He could have typed in the wrong ID.

The DB is secure but this part is open to the public where they have
write access to one table. I'm counting on the integrity of the
employees.

The ID text box is in the form header. The problem appears to be linked
to the way I have the record source query set up. It has a
[Forms].[FrmCurrent].[EmployeeID]
in a criteria field. and if the query result is empty I can not set
focus, but if the query has information then I can set focus.

Bob
 
Sorry for the delay Bob, been rather busy today :)

Bob Hughes said:
Wayne,
I do have Tab Index set to 0. I've always set that from the view, tab
order window.

In that case I can only assume that some VBA code is calling the SetFocus
property of another control - perhaps in the OnOpen/OnCurrent events?
Also just check that the TabStop property is set to True.
Sorry I did not explain my problem clearly.

The form is intended to show the status of an order to the user, but if
he does not have an order in progress I just tell her so & then attempt
to return to pick up a new user ID. He could have typed in the wrong ID.

The DB is secure but this part is open to the public where they have
write access to one table. I'm counting on the integrity of the
employees.

Ok, well the database security shouldn't affect anything here...
The ID text box is in the form header. The problem appears to be linked
to the way I have the record source query set up. It has a
[Forms].[FrmCurrent].[EmployeeID]
in a criteria field. and if the query result is empty I can not set
focus, but if the query has information then I can set focus.

This is a bit odd. I can't replicate your problem - however I am using
Acc2k3.
Perhaps try this...

Me.FormHeader.Controls.Item("EmployeeID").SetFocus

This specifically references the object from within its container, the
FormHeader. It sounds like an Access quirk but the above should fix it.
Obviously you also need to make sure you don't reference any other form
controls after the SetFocus call as anything could potentially take over the
focus.

If your still having problems, can you post your code that pops up the
message box and sets the focus, oh and tell us what version of Access too
please :)

Cheers,

Wayne Phillips
http://www.everythingaccess.com
 
Wayne,

Thanks for taking the time to respond to this problem.
I tried your setfocus suggestion with no success. I can not afford to
spend any more time on this, so I changed my form by adding a sub form.
The problem no longer exists. All the coding remains the same except for
a reference to the sub form
Forms!FrmCurrent.SubFrmCurrent.Form.Requery

Now if I can just figure how to program around my "Form background colour
problem" I'll be able to finish this whole thing off.

Bob

Sorry for the delay Bob, been rather busy today :)

Bob Hughes said:
Wayne,
I do have Tab Index set to 0. I've always set that from the view, tab
order window.

In that case I can only assume that some VBA code is calling the
SetFocus property of another control - perhaps in the OnOpen/OnCurrent
events? Also just check that the TabStop property is set to True.
Sorry I did not explain my problem clearly.

The form is intended to show the status of an order to the user, but
if he does not have an order in progress I just tell her so & then
attempt to return to pick up a new user ID. He could have typed in
the wrong ID.

The DB is secure but this part is open to the public where they have
write access to one table. I'm counting on the integrity of the
employees.

Ok, well the database security shouldn't affect anything here...
The ID text box is in the form header. The problem appears to be
linked to the way I have the record source query set up. It has a
[Forms].[FrmCurrent].[EmployeeID]
in a criteria field. and if the query result is empty I can not set
focus, but if the query has information then I can set focus.

This is a bit odd. I can't replicate your problem - however I am
using Acc2k3.
Perhaps try this...

Me.FormHeader.Controls.Item("EmployeeID").SetFocus

This specifically references the object from within its container, the
FormHeader. It sounds like an Access quirk but the above should fix
it. Obviously you also need to make sure you don't reference any other
form controls after the SetFocus call as anything could potentially
take over the focus.

If your still having problems, can you post your code that pops up the
message box and sets the focus, oh and tell us what version of Access
too please :)

Cheers,

Wayne Phillips
http://www.everythingaccess.com
 
Back
Top