Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check something before user goes to next record (2000)

    Sorry guys, I'm still trying to get more proficient with VBA. When the user clicks the default previous/next record button, I would like to perform a check on the form and then send out an error message if applicable. Then, I do not want the user to be able to advance to the next record unless the error is corrected (they must stay on the same record and fix the error). What is the best way to do this...? Thank you for your time and insight...

  2. #2
    4 Star Lounger
    Join Date
    May 2003
    Location
    Austin
    Posts
    401
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check something before user goes to next record (2000)

    Obviously, you're going to have to be more descriptive.
    What field are you 'validating'?
    How do you intend to compare it?
    There are several events you can use to 'trap' the user into remaining on the same record.
    Many of which disable those navigation keys, which is probably your best bet.
    We need a little more to go on. <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

  3. #3
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check something before user goes to next record (2000)

    Sorry about that. When the user clicks the "Update Address" command button, it opens textbox fields to allow them to make changes. It also opens up two other command buttons: "Save Address Changes" and "Cancel Address Changes." I want to make sure that once the user clicks the "Update Address" button, they cannot move onto another record until they either click "Save Address Changes" or "Cancel Address Changes." That is, they need to click one of those buttons before they move to another record. I have found that you can go to another record, but the "Save Address Changes" and "Cancel Address Changes" buttons appear on every record unless they actually click one of them! I don't really want to disable the default navigation buttons, but I could create my own navigation buttons if it will help solve this problem. What event/property allows you to capture when the recordset is moving onto a new record...?

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Check something before user goes to next record (2000)

    "Opening" fields or command buttons doesn't make sense. Do you mean you are making them visible or that you're unlocking them ... or are they on a popup form? If you're using a continuous form and are showing and hiding these controls based on a condition, then don't do it that way. Continuous forms show and hide controls in ALL the visible records, not just the current one. I'd suggest you put your buttons, at least, in the form header or footer, not in the detail section.

    The form events you're looking for are BeforeUpdate and Current. However, only the BeforeUpdate event can be cancelled to keep the user from moving to the next or previous record.
    Charlotte

  5. #5
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check something before user goes to next record (2000)

    OK, sorry this is so confusing. I will rephrase my question hopefully so it is easier to understand. How do you check ANY condition on a form once the user clicks next record/previous record. If the user doesn't follow the rules, then the current record remains until they perform some action.

    (If I use the Form_Current, and the user forgot to do something and then clicks the next record button, the error message appears, but the database still moves to the next record). Thank you all again.

  6. #6
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Check something before user goes to next record (2000)

    One way to detect whether the user has performed some required action is to check the dirty property of the form. If it's dirty, something has changed. You can check that on the lost focus event.
    Wendell

  7. #7
    Star Lounger
    Join Date
    Aug 2002
    Location
    Michigan, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check something before user goes to next record (2000)

    Charlotte, I would like to thank you for your time and for trying to help me out. I actually found the answer I was looking for in one of your previous threads located at: Re: Validation. The "needle in the haystack" for me was setting the Cancel = True on the Form_BeforeUpdate event. Thank you very much again.

    For others and because this discussion board is so incredibly awesome and helpful, I thought this sample code might be beneficial:

    Private Sub Form_BeforeUpdate (Cancel as Integer)
    If (the user did NOT follow your condition you set here) = True Then ' (that is, they violated your rule)
    Msgbox "Please correct your error here by doing blah, blah, blah"
    Cancel = TRUE
    YourControlName.SetFocus ' This sets the cursor back on the control that the user violated
    End If
    End Sub

Posting Permissions

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