Cursor should not move until value is entered in the control box .

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Need help I am facing problem, I tried with do while but it does not work,
the curser skip after giving message, to next field. I want that cursor
should not move or skip until the required value or any value is entered in
the textbox.
 
janjee said:
Need help I am facing problem, I tried with do while but it does not
work, the curser skip after giving message, to next field. I want
that cursor should not move or skip until the required value or any
value is entered in the textbox.

For almost all purposes, I don't think this is a good idea, for two
reasons: (1) you can't enforce this requirement unless you can also
force the focus into the control in the first place, and (2) if you
frustrate the users by not letting them out of the field, they may close
the form or even blast their way out of the database without doing other
things they ought to do. It's usually better, in my opinion, to
validate all required entries in the form's BeforeUpdate event, and
force the user to correct them then. That allows the user to fill out
forms in any order they find most practical.

That said, you can do it the way you want by using the control's Exit
event to enforce your requirement. Here's a sample event procedure:

'----- start of code -----
Private Sub YourControl_Exit(Cancel As Integer)

If IsNull(Me!YourControl) Then
MsgBox"You must enter something here before proceeding."
Cancel = True
End If

End Sub
'----- end of code -----
 
On the Lost Focus event, place validation that returns the focus to the
field as in...

[Validation code here]
MsgBox "Value Required"
Me.[fieldName].Setfocus
 
David C. Holley said:
On the Lost Focus event, place validation that returns the focus to
the field as in...

[Validation code here]
MsgBox "Value Required"
Me.[fieldName].Setfocus
Need help I am facing problem, I tried with do while but it does not
work, the curser skip after giving message, to next field. I want
that cursor should not move or skip until the required value or any
value is entered in the textbox.

I'm afraid that won't work, David. In the LostFocus event, the focus
hasn't actually left the control yet. but Access already knows where
it's going next. Setting the focus to the control in that event will
have no effect, because after that event the focus will move on to the
next control. The Exit event is the one to use for this, because it can
be Cancelled.
 
Hey! I'm comming off a 90 hour work week.

Dirk said:
On the Lost Focus event, place validation that returns the focus to
the field as in...

[Validation code here]
MsgBox "Value Required"
Me.[fieldName].Setfocus
Need help I am facing problem, I tried with do while but it does not
work, the curser skip after giving message, to next field. I want
that cursor should not move or skip until the required value or any
value is entered in the textbox.


I'm afraid that won't work, David. In the LostFocus event, the focus
hasn't actually left the control yet. but Access already knows where
it's going next. Setting the focus to the control in that event will
have no effect, because after that event the focus will move on to the
next control. The Exit event is the one to use for this, because it can
be Cancelled.
 
Back
Top