How to get user to fill each field before going to the next

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ql25
    New Member
    • Jun 2010
    • 3

    #1

    How to get user to fill each field before going to the next

    Dear Friends,

    I am a kind of new to acess VBA, and I have an access form with muliple fields. What I want is to write an access VBA code that asks user to fill each field before going to the next field so if there is any empty field the user can not take any action.

    Any help would be highly appritaited.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    This would require
    1. Setting all but the first control to Enabled = False
    2. After a given control is populated, in its OnExit or AfterUpdate event, enabling the next control
    3. Repeating this for all control
    4. Doing the above in the Form_Current event as well


    This approach is really ill-advised for several reasons. If there are many 'fields' you're talking about a huge amount of work
    1. End users each have their own approach to data entry and it seldom coincides with the developer's idea of what should be entered in what order
    2. If they don't have a piece of data at hand, most prefer to complete the rest of the record, retrieve the missing data, then fill in that control
    3. What do you do if they fill in a field, move on, filling in other fields, then come back and delete the data a previous field?


    Are you beginning to get an idea of what you're talking about?

    Checking for Null (empty) controls is usually done in the Form_BeforeUpda te, just prior to committing the data to the underlying table. Here's a simple example for two fields. It could be expanded, of course, and even coded to step thru all controls without actually naming them explicitly:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
     If IsNull(Me.Control1) Then
       MsgBox "Control1 Must Not Be Left Blank!"
       Cancel = True
       Control1.SetFocus
       Exit Sub
     End If
     If IsNull(Me.Control2) Then
       MsgBox "Control2 Must Not Be Left Blank!"
       Cancel = True
       Control2.SetFocus
       Exit Sub
     End If
    End Sub
    Your thoughts?

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Another common approach is to set the ValidationRule property of the underlying table. While in Design View of the table use Alt-Enter (or View / Properties from the menu) to see all the properties of the table. The ValidationRule property can be used to check settings where multiple fields are involved, particularly where the values in one field effect the valid values of another.

      Comment

      • ql25
        New Member
        • Jun 2010
        • 3

        #4
        Thnks guys for your replay but i am having truble with it , so would you please show me a way that i coulde loop all null fields in the current form showing a message that user should fil out each fields throught click button.

        Your help is highly appritiated.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          That's not how it works I'm afraid. We answer questions where we can, but you do the work.

          If you have a specific reason that you can't understand what we are saying then please explain this and we'll do what we can to help. Simply doing it for you is not an option. You need to give it a good attempt first and tell us where you struggle.

          Comment

          Working...