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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

require fields on an entry form?

Status
Not open for further replies.

misscrf

Technical User
Jun 7, 2004
1,344
0
0
US
I am getting close to finishing up my database. I am scarily trying to test it out and make sure that it is ready for the end users to start using.

One question that I have is with requiring fields. I try not to stop the user as much as possible, but at the same time I do not want to end up with a bunch of 1/2 records. Is there a best practices of how to control data entry while not angering the users?

I also have 3 subforms on a tabcontrol ( each on their own page) I have code in the onexit of the last field of each form. This makes it so that as a person tabs through from the first field on the main form, they can tab through the entire record.

This is for candidates who apply for a job with our law firm. So it tabs from the candidates salutation, through their info, down through the address form, then through the phone form, the application form, its activity form, and then to the save button ( I know Access saves as soon as a record is started/as long as its not locked, but I know that users like to feel like they are saving each record too.) My issue is that if a user has the cursor in the ie. zip field of the address subform, and they click up to the address1 field, or anywhere, they end up on the phone subform. The onexit code takes control. Is there any way to specify in code between tabbing and mouse clicks?

What I would like to do is have my onexit setfocus code run on tabbing away from the last field, but if mouse click happens then I would really like to supress that code. Can that be done, or am I having a funny dream?

Anyway, any other suggestions people may have for good tests to make sure my db is ready to roll out, I would really appreciate it. I do plan to split my db before I hand it out....


misscrf

It is never too late to become what you could have been ~ George Eliot
 
In the BeforeUpdate event of your Form, you can write code that checks to see if certain fields have been filled in. You can also check for legitimate values in those fields.

Example:

If isnull(me.LastName) then
msgbox "You must enter a Last Name"
me.LastName.SetFocus
cancel=true
end if

The .SetFocus returns the user to the field that must be filled in. The Cancel=true cancels the Record Update and keeps the user from exiting the record.

good luck!
 
Hi again misscrf...

Is there a best practices of how to control data entry while not angering the users?
EXCELLENT question!!! A tip of a huge iceburg. Here is a small start...

- "Best" way to ensure data is entered is to set the field as required using the table design view. By setting the field as "required" at the table level here will ensure the field always has data regardless of form or query being used to create the record.
- BeforeUpdate event procedure as outlined by CityBoy. You need to ensure each required field that is not controlled at the table level is checked for data. If the info is missing, set the focus per CityBoy's approach.
- Visual queues. A small astricks next to the form, or use a special coloured back ground or font colour. By using a consistent colouring approach will "train" your users what info is required. For example -- optional data - use a light yellow colour; required data - use light salmion.

onexit setfocus code run on tabbing away from the last field
If I understand you correctly, you want the OnExit event procedure to react differently. You can use this type of approach for the OnExit event (this is just an example, and more pseudo code to give you an example)....

First, sometimes you want to track field movements. You can capture this information by use OnEnter and OnExit event procedures for various controls. I would be interest in how others approach this but you can use one or two global variable or a hidden field on the form to capture the current / last field. Suppose you are moving from 1stField to 2ndField to 3rdField. For the OnEnter field you can verify that the last field was 1stField so you know you are moving "forward" through the form. If the last field was 3rdField, you know you are moving backwards.

Code:
Private 2ndField_OnEnter()

If Me.HiddenFieldCurrentField = "1stField" Then
   Me.HiddenFieldDirection = "Forward"

Else
   If Me.HiddenFieldCurrentField = "3rdField" Then
      Me.HiddenFieldDirection = "Backward"
   Else
      Me.HiddenFieldDirection = "Random"
   End If
End If

Me.HiddenFieldCurrentField = "2ndField"

Then for the OnExit
Code:
Dim booOkay as Boolean, intAction as Integer

booOkay = True
intAction = 0

'Verify required fields
If Nz(Me.1stRequiredNumberField, 0) = 0 Then
   booOkay = False
   intAction = 1
End If

If Nz(Me.2ndRequiredNumberFieldID, 0) = 0 Then
   booOkay = False
   intAction = 2
End If 

If Len(Nz(Me.1stRequiredTextField, "")) = 0 Then
   booOkay = False
   intAction = 3
End If

If Not IsDate(Me.1stRequiredDateField) Then
   booOkay = False
   intAction = 4
End If

If booOkay Then

   Select Case Me.HiddenFieldDirection 
      Case "Forward"
          Me.Parent!NextSubForm.SetFocus

      Case "Backward"
          Me.ParentForm.Afield.SetFocus

      'Random - mouse, dont control

   End Select

Else

   Select Case intAction
      Case 1
         Me.1stRequiredNumberField.SetFocus

      Case 2
         Me.2ndRequiredNumberField.SetFocus

      ' etc....

   End Select

End If

As stated, this is a bit of pseudo code -- I have not tested, and I suspect Roy or PHV or the Cajun or ... others can come up with better coding, but...
- You can test the data
- You can change the outcome / behaviour based on the testing

Richard
 
wow, thank you both for your help.

I have been unable to get onto tek-tips for a couple of days, but now that I am back I can respond.

I think you are both right. I need to decide what fields I want to have as required, and set them on the table level, and then use the before update.

as for the onexit. That was really another issue, but your solution would have worked well. I have onexit code that allows a user to tab from the first field of the first form, through each subform, back to the beginning. The problem is that some of the subforms, such as phone and address, a user may want to go back and add more. The on exit code was making the tabcontrol page jump.

To fix this, I made a text box and called it txtexit. Then I moved my code that was in the last field's onexit code to the txtexit field's onenter code. I made it the last field in the tab order, and have it placed under the last field. The user does not know it is there, but it sends them to the next subform and so on. The if the user doesn't want to follow the tabbing, they are free to click elsewhere without code firing off when they don't want it to.

Thank you all very much for the replies.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
hi all, I'm back. I have been working on other things. This application is out and being used. I am now revisiting this issue, as I am starting to make some more reports. I found that I can enter a candidate in, and if I dont enter at least an address type or phone type ( giving that candidate a primary address and phone record) then my repotrs wont pull any of the candidate's information. I need to be able to check when a person does a number of things, that at least the combos for phone type and address type have been chosen as something. I tried putting the following code in the form's before update, but since it is calling to a subform, the minute I tab TO the address combo, I get the message. The form is updating before I get the chance to skip the field.


Here is the lay out. A user can enter in candidate, their address, phone, application and activities. They should be able to move freely within any record.

What I want to do is check when the user is leaving a record. I would like to check when a user acts to leave a record (closing form, going to another record, etc) if either combo is empty (no primary contact info) then it gives the message and goes back to the combo that is empty.

Here is the code I have. If anyone can help me find the right place to put it, I would really appreciate it. Thank you,

Code:
If IsNull(Me.[subAddressEntry].Form![cmbAddressTypeID]) Then
   msgbox "You must enter an Address"
   Me.[subAddressEntry].Form![cmbAddressTypeID].SetFocus
   Cancel = True
ElseIf IsNull(Me.[subPhoneEntry].Form![cmbPhoneTypeID]) Then
   msgbox "You must enter a Phone"
   Me.[subPhoneEntry].Form![cmbPhoneTypeID].SetFocus
   Cancel = True
Else: Cancel = False
End If



If I can't figure this out, I am thinking of making a new address type and phone type. Call it "none chosen" and then make that a default selection. Then one would always be chosen...I think. I would like to avoid that though.

Thanks again.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
In the AfterUpdate event procedure of the mainform:
If IsNull(Me!subAddressEntry.Form!cmbAddressTypeID) Then
Me!subAddressEntry.SetFocus
Me!subAddressEntry.Form!cmbAddressTypeID.SetFocus
ElseIf IsNull(Me!subPhoneEntry.Form!cmbPhoneTypeID) Then
Me.subPhoneEntry.SetFocus
Me.subPhoneEntry.Form!cmbPhoneTypeID.SetFocus
End If

If the BeforeUpdate event procedure of subAddressEntry:
If IsNull(Me!cmbAddressTypeID) Then
MsgBox "You must enter an Address"
Me!cmbAddressTypeID.SetFocus
Cancel = True
End If

And similar code in the BeforeUpdate event procedure of subPhoneEntry.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you for responding PHV. I really appreciate it.


I like the look of this, because I am sure it will work. I hope I am not being stubborn here, but I have some concerns.

The user should be able to move freely within any record, and only be bothered when they try to leave, if important information is still empty. I dont want to control how they enter ('you must enter this first!' lol) just that they do enter it in the end.


I have tabbing set to take them from the first field on the main form through the subforms. Its nice. Thing is that it takes them from the candidate info straight to address. they might land on it, but decide to skip to the application. I want them to be able to come back and enter the address in. Then I jsut want it to alert them if they try to leave that candidate and one of those is empty. Will this allow them free movement like that?

Thank you again.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top