Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I prevent the data enterer from proceeding to next field?

Status
Not open for further replies.

slaman

Programmer
Jun 8, 2001
47
CA
I have a secondary index entitled "Corporation Name". The database has an AutoNumber primary key, but the Corporation Name field has to also be unique. I have created a form for data entry for all the needed information; however, I am encountering a small obstacle. I want the FOCUS to immediately go to the "Corporation Name" field. Before moving to the next field, I want to make sure its:

a) not null or empty
b) unique

If not, I want to display a little message in the status bar saying you cannot proceed without a valid Corporation Name, and then I want to prevent the user from moving to any other field (except clicking the "Done" button perhaps). This will prevent any errors with refreshes or newrecords.

Please let me know the methods to do this - I'm a Corel Paradox user who switched over recently, so be kind =P
 
Well I am finally able to determine if the field is blank or not and display a message if it will, but again a few problems:

-I cant prevent focus from changing to next field
-Why must I use NOT IsNull and #IF Not corpName? If I remove them both - it wont execute (odd no?)

Private Sub Corporation_Name_Exit(Cancel As Integer)
Dim corpName As Boolean
corpName = Not IsNull([Corporation Name])
#If Not corpName Then
MsgBox "The Corporation Name cannot be left blank: if", vbOKOnly
[Corporation Name].SetFocus
#End If
End Sub
 
In the properties of the control, go the the Validation Rule and set Is Not Null and provide a Validation Text letting the user know what they are doing wrong. To make sure all are unique, go into your table design and change the index to Yes (No Duplicates). Then duplicates will not be allowed.

HTH Joe Miller
joe.miller@flotech.net
 
Wow, this is a lot simpler than I had first thought.

For the Validation Rule, I put the following:

[Corporation Name]=Not Null And [Corporation Name]=Not ""

which simply displays the Validation Rule Text for ANYTHING that is input for the field (including if its left blank)

Plus if it IS left blank, I still want to allow the option for the user to click the "Done" button. As it stands, if they leave it blank, they are stuck in that field's control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top