Set focus

  • Thread starter Thread starter TM
  • Start date Start date
T

TM

Hello,

Having a difficult time trying to set the focus back to a control that has
an error.
After tabbing out of the field without changing the contents. the value of
TYPECDE should be null.
The following code is attached to the On Exit Event.


If IsNull(Me.TYPECDE) Then
MsgBox ("Type Code must be a 1 or 2")
TYPECDE.SetFocus
End If
If Me.TYPECDE = "1" Then Me.txtTranType = "Pickup"
If Me.TYPECDE = "2" Then Me.txtTranType = "Delivery"


MsgBox works fine, but the cursor always ends up in the next control.

Any thoughts?
 
I had a similar problem. I think the "setfocus" needs to be the last
command in the string.


Hello,

Having a difficult time trying to set the focus back to a control that has
an error.
After tabbing out of the field without changing the contents. the value of
TYPECDE should be null.
The following code is attached to the On Exit Event.


If IsNull(Me.TYPECDE) Then
MsgBox ("Type Code must be a 1 or 2")
TYPECDE.SetFocus
End If
If Me.TYPECDE = "1" Then Me.txtTranType = "Pickup"
If Me.TYPECDE = "2" Then Me.txtTranType = "Delivery"


MsgBox works fine, but the cursor always ends up in the next control.

Any thoughts?
 
Is it attached to the On Exit event of the TYPECDE control?

If so, then you can set Cancel = True instead of the
setfocus.



Chris Nebinger
 
TM said:
Hello,

Having a difficult time trying to set the focus back to a control that has
an error.
After tabbing out of the field without changing the contents. the value of
TYPECDE should be null.
The following code is attached to the On Exit Event.


If IsNull(Me.TYPECDE) Then
MsgBox ("Type Code must be a 1 or 2")
TYPECDE.SetFocus
End If
If Me.TYPECDE = "1" Then Me.txtTranType = "Pickup"
If Me.TYPECDE = "2" Then Me.txtTranType = "Delivery"


MsgBox works fine, but the cursor always ends up in the next control.

Any thoughts?
I know this treads a few months old, but having just had the same problem
and searched the NG for an answer, I thought I might post my solution to the
problem:

If IsNull([Surname]) Then
DoCmd.OpenForm FormName:="Opps6Frm"
Me![FirstName].SetFocus
Me![Surname].SetFocus
End If

I know it has been said that a Tab can be used, but then I dont know (yet)
how to do that in VBA. But the focus has to go to the field before the last
and then pushed onto the required field, that much I did find out:o)

Philip Martin.
 
Back
Top