Set Focus

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!
 
B

Beetle

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
 
P

PeterM

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?
 
B

Beetle

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

PeterM

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