return focus to previous control

  • Thread starter Thread starter Mark Kubicki
  • Start date Start date
M

Mark Kubicki

I have a simple sub that check to see if a value has been entered whenthe
user extis that control
but, it is not returning... the cuser remains at the next control that was
clicked on...

Any thoughts would be appreciated
thanks inadvance,
mark

here's my code

Private Sub txtType_Exit(Cancel As Integer)
If Len(Nz(Me.txtType)) < 1 Then
responce = MsgBox("You must enter a fixtue type before moving on..."
& Chr(10) & Chr(13) & _
"Please try again", vbOKOnly + vbCritical, "Missing Fixture
Type")
Me.txtType.SetFocus
Else
Me.txtType = UCase(Me.txtType)
End If
End Sub
 
Maybe it's better to put the check in the before update event of the textbox
instead of the on exit event. Your focus will still be in the textbox if you
use the before update and if the check fails you can use the cancel argument
to exit the code. No need to set the focus again because it will still be
there.

Just a thought...
 
i've re-written the code to be:

Private Sub txtType_BeforeUpdate(Cancel As Integer)
If Len(Nz(Me.txtType)) < 1 Then
responce = MsgBox("You must enter a fixtue type before moving
on..." _
& Chr(10) & Chr(13) _
& "Please try again", vbOKOnly + vbCritical,
"Missing Fixture Type")
Else
Me.txtType = UCase(Me.txtType)
End If
End Sub


BUT,
I've never used the cancel event (self-taught newbie here), and am not
figuring out how to... on " <1 " the code works correctly, however, if the
value is " =<1 " the "Else" clause ought to execute .. it does not, and i
can't exit the control either

could you help meout on this part also?

THANKS
-m.

---------------------------------------------------------
 
Back
Top