Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defective behaviour of control focus

Status
Not open for further replies.

Bresart

Programmer
Feb 14, 2007
314
ES
Hi, in a simple form there's a combo for applying a filter by name field: a name can be selected from the list or can be written.

The filter is applied on the event AfterUpdate of the combo, as follows:

Dim db, queryDef As Variant, strFilter as String

strFilter = "SELECT tblTaxonomy.Id " & _
"FROM tblTaxonomy " & _
"WHERE (((tblTaxonomy.commonName) Like " & _
"" & Me.combo.Value & ")) " & _
"GROUP BY tblTaxonomy.Id;"

Set db = CurrentDb()
Set queryDef = db.QueryDefs("qryFilter")
queryDef.SQL = strFilter
DoCmd.ApplyFilter "qryFilter"


After applying the filter the focus must go to the first control in the form, that is what the Form_Current event does:

DoCmd.GoToControl "firstControlName"


but when the name is written in the combo (not selected), the focus goes to the form second control, no matter if the end of the AfterUpdate event code is

DoCmd.GoToControl "firstControlName"


However, if the name is selected in the combo (not written), there's no problem, the focus goes to the first control after applying the filter.


I have tried:

- writing all the code in a command button instead of in the AfterUpdate event of the combo, and it works perfectly.
- writing all the code in a private function instead of in the AfterUpdate event of the combo and calling to this function from the AfterUpdate event of the combo, and it worked the first times but when opening again the DB after making a backup copy it hasn’t surprisingly worked anymore.
- writing some focus checking msgbox in the code in the AfterUpdate event of the combo, it works without any problem.


Thanks for any help given.
 
I have seen where the problem is, and have posted a new thread about: Running AfterUpdate control event when key Enter has its own behaviour.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top