Set the focus

  • Thread starter Thread starter dhstein
  • Start date Start date
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.
 
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 = ""
 
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.
 
Back
Top