return focus to previous control

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
 
M

Maurice

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

Mark Kubicki

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.

---------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top