VBOkCancel coding

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

I have a form that requires a field to contain data so I would like to have
a message box popup that tells the user that the field they just tabbed out
of requires and input. I would like to let them have the choice to either go
to the next record or go back to the filed the just exited out of.

I would like the OK button to be clicked and return to the unfinished field
or if they click the CANCEL button move on to the next field.

Please advise on the coding required for this problem.

Thanks in anticipation to who ever answers me.

JT
 
JT said:
I have a form that requires a field to contain data so I would like
to have a message box popup that tells the user that the field they
just tabbed out of requires and input. I would like to let them have
the choice to either go to the next record or go back to the filed
the just exited out of.
I would like the OK button to be clicked and return to the unfinished
field or if they click the CANCEL button move on to the next field.

Please advise on the coding required for this problem.

Thanks in anticipation to who ever answers me.

JT

Why would you allow them to move to the next record if the field is required?
That would be the opposite of required wouldn't it?

The best way to handle this is to make the field required at the table level.
Then Access will automatically force them to make an entry. If you try to warn
them when they tab out of the control what happens if they use the mouse and
never tab into the control in the first place?
 
JT,

I agree with Rick. Normally if a field is required, the user must finish the
input before he can continue to next record. However, the following can be
used to tackle the issue:

Private Sub Text0_Exit(Cancel As Integer)
If IsNull(Me!Text0) = True Then
If MsgBox("This is cumpulsary field.", vbOKCancel, "Invalid input")
= vbOK Then
Me!Text0.SetFocus
Else
DoCmd.GoToRecord , , acPrevious
End If
End If
End Sub

Insert the above in the On Exit event of the text box. In the example above,
I used Text0 as the field name. Please change to the name of your text field.

Hope this helps you.
 
Back
Top