Lock user to a field

danikuper

Registered User.
Local time
Today, 14:02
Joined
Feb 6, 2003
Messages
147
Is there a way to, once the user tabs to a field in a form he can only proceed to the next one after entering data?

And can I prevent the user from using the mouse in the form so he can only tab through the fields in the order I want?

thanks!!!
 
1) You could set the fields property to "Required" but that only stops him from exiting the record without an entry. Does what you want just not when you want.

2) Only by disabling the mouse via VBA and I'm not sure that is possible.
 
Yes, setting the field as "required" will not solve my problem... maybe if I add some code to the "on focus" or "on click" event of the control?

Any ideas?
thanks!!!
 
On Exit or Focus would be where this needs to be but I'm not good enough with VBA yet to help you out. Perhaps one of the VBA gurus?
 
Your idea will require code for "each" field. I suggest that you set a Validation Rule for each field that you do not want empty (Null) when the new record is saved. Open your table in design view and set the Validation Rule to Is Not Null and key a message in the Validation Text to give the user a meaningful message as to what they did wrong.

To answer your original question...you have to test if the field is Null when they exit the field, then you have to set the focus to another field before you can set the focus back to the offending field that you are testing for Null. My example is testing a field named tbTest, if the tbTest field is Null when the users tries to move to another field, I am setting the focus to the tbAnotherField field and then back to the tbTest field.

The below code will set the focus back to the tbTest field if it is empty and also if they are tabbing our mousing around.

Private Sub tbTest_Exit(Cancel As Integer)

If Nz(tbTest) = "" Then
Me.tbAnotherField.SetFocus
Me.tbTest.SetFocus
End If

End Sub

HTH
 
Last edited:
This is more efficient...

Private Sub tbTest_Exit(Cancel As Integer)

If Nz(tbTest) = "" Then
Cancel = True
End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom