Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2003
    Posts
    40

    Unanswered: Verifying information as it is entered

    I am trying to validate information as the user enters it into a form. It is easy enough to validate whether or not what they have entered is vaildate date using the BeforeUpdate procedure and an if statement. However, I also want the user to get an error message if they don't enter anything at all. My first attempt at doing this is by using LostFocus and then just calling my BeforeUpdate procedure from there. Sometimes it works and sometimes it does work.
    Also, when I can get the LostFocus to work it does not reset the Focus to the field like it would if they entered invalid data. Here is my code that doesn't work:

    Private Sub MemberName_BeforeUpdate(Cancel As Integer)
    If IsNull(MemberName.Value) Then
    MsgBox "Please enter the name of the team member", vbOKOnly
    Cancel = True
    End If

    End Sub

    Private Sub MemberName_LostFocus()
    MemberName_BeforeUpdate (False)
    End Sub

    Any help would be appreciated. Thanks!

  2. #2
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Why not just make MemberName a required field in the Table Design. Let Access enforce the rule for you. You can also respond with custom error messages by using OnError Goto
    All code ADO/ADOX unless otherwise specified.
    Mike.

  3. #3
    Join Date
    Nov 2003
    Posts
    40
    If I do it that way, I am still not sure how to get it to refocus on the field that wasn't filled in. The SetFocus hasn't been working for me.

  4. #4
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Let the error occur and record the number. There's a way to determine all the error numbers and their description, but I find this way is easier.

    In the error handler, check the error number, if it's the one you recorded, give your error message and use Me.MemberName.SetFocus
    All code ADO/ADOX unless otherwise specified.
    Mike.

  5. #5
    Join Date
    Nov 2003
    Posts
    40
    I don't get the required field error until after I have filled out the entire record (or gone to the next line) so at what point do a check for the error message?

  6. #6
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Whoops! I tried to give you two solutions at once.

    To accomplish what I think you are looking for (don't use the Required property of the table's column), use the Form_BeforeUpdate event:

    Sub Form_BeforeUpdate(Cancel As Integer)

    If IsNull(Me.MemberName) then
    MsgBox "Member Name must be entered"
    Me.MemberName.SetFocus
    Cancel = True
    End If

    End Sub

    This will get you the custom error message, and set the focus.
    All code ADO/ADOX unless otherwise specified.
    Mike.

  7. #7
    Join Date
    Nov 2003
    Posts
    40

    Talking

    Ha! IT WORKED!
    I have tried almost 6 different things to try to accomplish that one little task, and your solution worked!
    Thank you so much!

Posting Permissions

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