Set Focus

  • Thread starter Thread starter PeterM
  • Start date Start date
P

PeterM

On my data entry form using AC2003. I have the following as the OnChange
event for a drop down combobox...

Private Sub Type_Change()
If IsNull(Me.Type) Then
MsgBox "Type is required.", vbCritical, "Data Entry Error"
Me.Type.SetFocus
End If

End Sub

When I tab thru the Type field, I get the msgbox with the error message but
the focus goes to the next field in the tab order and does not go back to the
combobox....why?

Thanks in advance for your help!
 
Use the Before Update event. This wil prevent focus from ever moving off the
control if it is null.

Private Sub Type_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Type) Then
MsgBox "Type is required.", vbCritical, "Data Entry Error"
Cancel = True
End If

End Sub
 
thanks for responding but that doesn't work, the beforeupdate event is not
triggered if I tab thru the combobox without selecting an entry, any other
ideas?
 
Yes. Take your original code and put it in the Got Focus and the On Click
event of the other control (the one that follows the combo box). The reason i
suggest both events is that for, some reason, the Got Focus event doesn't
fire if a mouse click is used to enter a control.
 
It worked....thank you very much!

Beetle said:
Yes. Take your original code and put it in the Got Focus and the On Click
event of the other control (the one that follows the combo box). The reason i
suggest both events is that for, some reason, the Got Focus event doesn't
fire if a mouse click is used to enter a control.
 
Checking for Null values in textboxes should always be done in the form's
BeforeUpdate event! Doing it in an event of the textbox, whether Got Focus or
On Click or whatever requires that the user actually visits the textbox, and
you have no reasonable way of guarantying this!
If the code's in the form's BeforeUpdate event, it will be checked even if
the textbox is never entered.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
 
Back
Top