Results 1 to 6 of 6
  1. #1
    peterFisp is offline Novice
    Windows 10 Access 2003
    Join Date
    Sep 2019
    Location
    Australia
    Posts
    18

    Custom record navigation buttons on a form

    Hi guys,


    New to the forum but not to Access. While I used it since the mid-nineties (for what I considered some fancy stuff; and still use some through a Virtual Machine with XP Pro), I never really got the hang of VB and what I need to do to properly address a database.
    And I did earlier hi-jack a thread, thinking that was the way to go. But I was told that not to be so. So I apologize for that.

    So here is my question: As for the above, I am trying to add custom navigation buttons to my one form. When I simply add the following code:


    Code:
    Private Sub cmdPrevious_Click()
    
        MsgBox "Pete: this is on form current at the very beginning   will NOT display; so what does that mean?", vbOKOnly    ' MESSAGE will NOT display
    
    
    On Error GoTo Err_cmdPrevious_Click
     
        DoCmd.GoToRecord , , acPrevious
     
    Exit_cmdPrevious_Click:
        Exit Sub
     
    Err_cmdPrevious_Click:
        Select Case Err.Number
            Case 2105
                MsgBox "Pete: you are already at the beginning", vbOKOnly
            Case Else
                MsgBox Err.Number & "-" & Err.Description
            End Select
        Resume Exit_cmdPrevious_Click
       
    End Sub

    To my knowledge, the only other entry in all of 'code' is the prefix of "Option Compare Database" at the top of the form.


    Do I need things like
    Set db
    Set RS???
    to make this work. As I said, this kind of stuff I never quite worked out (which is why my older DB will not convert higher than Access 97).
    I know I am asking a lot but would really appreciate your input since I am keen to make this form work for me.

    And if I may add, my form is based on a Recordset and has Recordtype of Dynaset. Also, the Next, Previous and New buttons are in the Form Header; with the First and Last row buttons in the footer of the form.

    I know I am asking a lot but would really appreciate your input since I am keen to make this form work for me.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    When I simply add the following code:
    Is there something missing after this - like an explanation of the problem or even if there is one?
    EVERY module should also have OPTION EXPLICIT or as the Wise One once said, "you deserve what you get" (he was talking about grief). It is an option in the vb editor "Require variable declaration". Advise you to turn it on and add the line to every existing module and compile each as you go (turning it on does not add the condition to existing modules). Don't be surprised if you catch some errors.

    Second, please post more than a few lines of code within code tags (# on forum toolbar).

    Lastly, if you must use custom buttons, you have to code for each possibility per button; i.e. if next and previous, you have to capture that there is no next or previous. Same for last and first as you might already be there. You do know that a form with single record view automatically contains record navigation controls by default, so no coding required?
    Last edited by Micron; 09-12-2019 at 08:17 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    peterFisp is offline Novice
    Windows 10 Access 2003
    Join Date
    Sep 2019
    Location
    Australia
    Posts
    18
    Quote Originally Posted by Micron View Post
    Is there something missing after this - like an explanation of the problem or even if there is one?
    EVERY module should also have OPTION EXPLICIT or as the Wise One once said, "you deserve what you get" (he was talking about grief). It is an option in the vb editor "Require variable declaration". Advise you to turn it on and add the line to every existing module and compile each as you go (turning it on does not add the condition to existing modules). Don't be surprised if you catch some errors.

    Second, please post more than a few lines of code within code tags (# on forum toolbar).

    Lastly, if you must use custom buttons, you have to code for each possibility per button; i.e. if next and previous, you have to capture that there is no next or previous. Same for last and first as you might already be there. You do know that a form with single record view automatically contains record navigation controls by default, so no coding required?
    OK, there is nothing missing. I was just trying to express the fact that what I include (with the missing tags, sorry) is all there is.
    And there is certainly a problem: those buttons just do not work. My thinking from including what I hope is an unconditional message, is the buttons and their code are ignored.

    And yes, I am fully aware of the form-based standard buttons. I just always find them too small. And I do have more code to check whether I am on First or Last Row; and then disable or enable the relevant buttons.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    So you are saying that when you click the button that has this code for the button click event nothing happens. No messages at all and no navigation?
    Then your code is possibly disconnected from the control. To test, open form in design view and on property sheet, click the ellipses (...) for the button click event. Event code for this should appear and if it was disconnected, should now be reconnected. If it still doesn't appear to run after that, then put a break point on the first line of the code and click the button again. If it doesn't stop at the break point, there is something else wrong.

    As written, your first message will never show if there is an error. Your second will not show if there is an error but it is not 2105. Only the last message would show in that case.

    P.S. you can always go back to your post and add the code tags (for a limited time). Usually helps us if you also use some sort of standard indentation.

  5. #5
    peterFisp is offline Novice
    Windows 10 Access 2007
    Join Date
    Sep 2019
    Location
    Australia
    Posts
    18

    Thumbs up Review Trust Centre settings

    OK, Yes that is what I am saying: No effect whatever, no navigation and no error messages, nothing.
    Did add those code tags, thanks (not using forums a lot).
    did add a break point on a number of different code lines: no effect whatever.
    However, my form keeps working nicely, with the standard buttons.

    And then there was light; talk about the blind hen and the corn. You said that in the above case, ie break, etc, and still nothing, that something else was wrong. So I started thinking about what that might be. And I remembered that I would on occasion get that Trust Center message. So I explored that and found a setting that prevents the running of all macros.

    Changed that to enable all and that was the issue. So presumably code is considered like a macro; or treated as one.

    Either way, the first button works fine, with my test messages displaying as well.

    And so I thank you kindly for persisting, and for your input.
    Attached Thumbnails Attached Thumbnails MyForm.jpg  

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    That never entered my mind because it's been so long since I had to deal with it. My recollection was that when you open a db, if code is not trusted it says so right at the top of the application window. You are correct in that no code will run. Macros are a form of code, and not even an AutoExec macro will run, nor will code behind a form that is set to be the opening form in db options. Possibly even ribbon xml will not run, but then as I said, it's been a while since I was on a 'strange' pc. Glad you figured it out.

    (it blows me away that anyone would 'invest' $400 in such a device)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2016, 11:13 AM
  2. Replies: 4
    Last Post: 11-06-2014, 05:35 AM
  3. Navigation Record Buttons in Forms
    By jaarons in forum Forms
    Replies: 4
    Last Post: 01-02-2013, 09:57 PM
  4. Replies: 1
    Last Post: 06-01-2011, 06:44 PM
  5. Record navigation buttons work backward
    By jonesy29847 in forum Access
    Replies: 22
    Last Post: 04-11-2011, 06:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums