Set the focus

D

dhstein

This Code works:
Private Sub cbxFindVendor_LostFocus()
If cbxFindVendor.Visible Then

Me.cbxWeightByVendor.SetFocus
cbxFindVendor.Value = ""
cbxFindVendor.Visible = False
End If
End Sub

This code doesn't work:

Private Sub cbxFindVendor_AfterUpdate()

' ...Other Code here - Dlookups ...

If cbxFindVendor.Visible Then

Me.cbxWeightByVendor.SetFocus
cbxFindVendor.Value = ""
cbxFindVendor.Visible = False
End If

Error is :
Runtime error 2110
Microsoft Office Access can't set the focus to the control cbxWeightByVendor

BTW the control is visible - and never gets hidden

Any ideas are appreciated. Thanks.
 
A

Allen Browne

AfterUpdate is too early. Even if you could SetFocus in that event, the
focus is not leaving the combo yet, so after you do your thing, Access would
set the focus to the following control (meaning that your code would not
appear to work.

Did you really intend to set the value to a zero-length string? Normally it
would be preferable to set it to Null, i.e.:
Me.cbxFindVendor = Null
rather than:
cbxFindVendor.Value = ""
 
H

he_feihong

dhstein said:
This Code works:
Private Sub cbxFindVendor_LostFocus()
If cbxFindVendor.Visible Then

Me.cbxWeightByVendor.SetFocus
cbxFindVendor.Value = ""
cbxFindVendor.Visible = False
End If
End Sub

This code doesn't work:

Private Sub cbxFindVendor_AfterUpdate()

' ...Other Code here - Dlookups ...

If cbxFindVendor.Visible Then

Me.cbxWeightByVendor.SetFocus
cbxFindVendor.Value = ""
cbxFindVendor.Visible = False
End If

Error is :
Runtime error 2110
Microsoft Office Access can't set the focus to the control
cbxWeightByVendor

BTW the control is visible - and never gets hidden

Any ideas are appreciated. Thanks.
 
Top