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.
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.