Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Required Fields (2003)

    Hi,

    I put the following codes in form_BeforeUpdate event. Then I have three fields with "Require" tab entry.

    Dim ctl As Control
    For Each ctl In Me
    If ctl.Tag = "Required" Then
    If IsNull(ctl) Or ctl = "" Then
    MsgBox "You must complete all required fields to continue", vbCritical, "Required Field"
    ctl.SetFocus
    Cancel = True
    End If
    End If
    Next
    Set ctl = Nothing

    By using the above codes, if I am missing two of required fields and click add new record button, then error message pops up twice and the form is restart. I would like the error message pops up and stop to let user to enter the missing required field data one by one instead of all the data is gone with new form start.

    Thanks in advance.

    Regards

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Required Fields (2003)

    Try this:
    <code>
    Dim ctl As Control
    For Each ctl In Me
    If ctl.Tag = "Required" Then
    If IsNull(ctl) Or ctl = "" Then
    MsgBox "You must complete all required fields to continue", _
    vbCritical, "Required Field"
    ctl.SetFocus
    Cancel = True
    Exit For
    End If
    End If
    Next ctl
    Set ctl = Nothing
    </code>
    The code leaves the For ... Next loop if a blank required field is encountered.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required Fields (2003)

    Thanks, Hans.

    I tried your codes, but the error message pops up and the form is restarted.

    Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Required Fields (2003)

    What exactly do you mean by "the form is restarted"?

  5. #5
    4 Star Lounger
    Join Date
    Feb 2006
    Posts
    504
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Required Fields (2003)

    As I click "Add new record" button, then the error message pops up. The form will close it by itself, then a new entry form appears.

    Regards

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Required Fields (2003)

    That must have some other cause. The code as posted doesn't do that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •