Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Navigational buttons - Again! (A2K)

    I swear I have to be retrained after every posting.

    I have the following code as a Public Function so that when someone presses F10, which is set as a macro key inside of AutoKeys, they go to the next record which works, but allows them to F10 past the last record and into a
    Cheers,
    Andy

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

    Re: Navigational buttons - Again! (A2K)

    The test code you posted is *not* for preventing users from going beyond the last record, but for preventing them from moving before the first record.

    Also, your naming is confusing - butGoNextRecord is a function, while butGoPrevious is a command button. You can't treat them as if they're interchangeable.

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Navigational buttons - Again! (A2K)

    Hans,

    A database is worth a thousand confused words. Please see attached and hopefully it'll clarify what I'm trying to do.

    Thanks again for your ongoing patience,

    ps. Just noticed it was 11 records, not 9. The theory is the same whatever the number.
    Cheers,
    Andy

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Navigational buttons - Again! (A2K)

    I think think the easy solution is to set the allow additons property to false, and set it back to true when you want to add a new record. That is generally how I do it.

    But try this

    Public Function butGoNextRecord() 'GoTo Next Record - F10
    On Error GoTo Err_butGoNextRecord
    Dim frm As Form
    Set frm = Screen.ActiveForm

    If frm.CurrentRecord < frm.RecordsetClone.RecordCount Then
    DoCmd.GoToRecord , , acNext
    End If
    Regards
    John



  5. #5
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Navigational buttons - Again! (A2K)

    John,

    Thanks kindly for jumping in. Your solution worked perfectly.

    Which begs the question as to why you think a one-time few lines of code in a module is not easier than having to remember to create ongoing extra coding every time you have to create a new form in a System. Your solution is elegant and in place and there is no need to go back and make changes to all of the existing and future forms.

    I'm definetly sticking to your "But try this".

    Thanks again very much,
    Cheers,
    Andy

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Navigational buttons - Again! (A2K)

    I am glad it worked.

    I suppose it is a matter or personal preference, and perhaps one of habit as well.

    If you allow additions, then you have to be sure that you stop people accidentally creating new records by any method that they might do so.

    In this case a few extra lines of code stopped the F10 method, some other lines of code stopped the navigation buttons, something else stops the mouse wheel etc.
    Are you going to stop users going CTRL ++ or going to Records...Data Entry.

    I have been caught in the past when I had not anticipated users creating records with the mouse wheel, but they did.
    So I prefer to stop these (any other methods I have not thought of) by setting AllowAdditions to NO. I then have a command button for creating new records and the first thing it does is set AlllowAdditions to true. Then I set it back to false in the afterupdate method of a field that is required.
    Regards
    John



  7. #7
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Navigational buttons - Again! (A2K)

    John,

    Good Logic!

    If we'd had this "discussion" before I got going on this particular project, I would have taken your approach to this problem. That's not to say that I don't mind going back after this project is up and running and semi-stable and changing my current code. But it takes away the excitement of how you're going to get surprised by your users! Never have so few circumvented so much by doing so little.

    Thanks again for your input. This little "discussion" is being pasted into my ongoing Access Notes.
    Cheers,
    Andy

Posting Permissions

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