Results 1 to 7 of 7
  1. #1
    THE STUDENT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    11

    Navigational Buttons STOP working !!

    Code:
    Private Sub Command47_Click()
       On Error GoTo Err_Command47_Click
       If Me.Command47.Caption = "Add Customer" Then
          'Add Customer enable save button and turn name to cancel
          DoCmd.GoToRecord , , acNewRec
          Me.sav_btn.Enabled = True
          Me.Command47.Caption = "Cancel"
          Me.Previous.Enabled = False
          Me.Next.Enabled = False
          Me.Command26.Enabled = False
          Me.Command25.Enabled = False
    Exit_Command47_Click:
          Exit Sub
    Err_Command47_Click:
          MsgBox Err.Description
          Resume Exit_Command47_Click
       Else
          'Cancel everything
          If Me.Dirty Then
             Me.Undo
          End If
          Me.sav_btn.Enabled = False
          Me.Command47.Caption = "Add Customer"
          Me.Requery
       End If
    End Sub

    I recently used the following code for my add customer form and it was working perfect! When the user clicked on add customer button the save button would enable (its disabled when the form opens) and the add customer button would the change to 'cancel', plus all other navigation buttons would be disable untill cancel was clicked again. (menu, previous, next & search) Now when the add customer button is clicked the save button is being enabled but when cancel is clicked the rest of the buttons are staying disabled, they would normally go back to normal. I checked with the properties for the from and navigational buttons are enabled, the code that is above is whats there, im thinking it might be something in the form properties ???? Whats even more strange is I had a back -up of the database so I thought i would just replace the form and move on, but to my dismay that one is doing the same thing !!!

    Can someone please advise



    THE STUDENT

  2. #2
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742

    Read the Code like a computer does, and you shall know....

    Step line by line through the code, and you wil find that you're missing some code there. You need an "End IF" for the If condition, and it looks like maybe the "else" got deleted.

    What happens in that code if the button caption is "Cancel" and the button is pressed?

    Ah, what happened is some code (the exit and error code) got moved. Here's the correct order.

    Code:
    Private Sub Command47_Click()
       On Error GoTo Err_Command47_Click
       If Me.Command47.Caption = "Add Customer" Then
          'Add Customer enable save button and turn name to cancel
          DoCmd.GoToRecord , , acNewRec
          Me.sav_btn.Enabled = True
          Me.Command47.Caption = "Cancel"
          Me.Previous.Enabled = False
          Me.Next.Enabled = False
          Me.Command26.Enabled = False
          Me.Command25.Enabled = False
       Else
          'Cancel everything
          If Me.Dirty Then
             Me.Undo
          End If
          Me.sav_btn.Enabled = False
          Me.Command47.Caption = "Add Customer"
          Me.Requery
       End If
    Exit_Command47_Click:
          Exit Sub
    Err_Command47_Click:
          MsgBox Err.Description
          Resume Exit_Command47_Click
    End Sub

    Your lesson for the day is "back up your database early and often".

  3. #3
    THE STUDENT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    11
    I tried your code dale, and it is still doing the same thing, when the 'add customer' button is pressed the save button is enabled and all other buttons are disabled. When cancel is pressed the only button that is being enabled is the add customer button, all others are staying disabled.
    I did back up before this started happening, when I opened up the back-up it did the very same as the database I was working on! can it be something to do with the form properties ??

    Thanks for your response

    THE STUDENT

  4. #4
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    This next bit is called "Teaching a Man to Fish".

    You can do this.

    Please step, line by line, through the code.

    Find the place where, in your opinion, the code *should* re-enable the buttons that were disabled. Is there code there to do it?

    Hint 1: look at each line immediately before the "Else" and see if a corresponding line, setting the enabled property the other way (FALSE/TRUE), can be found after the Else.

    Provide the four missing lines.

    Hint 2: Place the needed lines immediately before "Me.Requery".

  5. #5
    THE STUDENT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    11
    lol, ok DAL, im guessing im a student and I should learn to code, the good news is it worked I placed the same line that was false immediately before "Me.Requery" but with true and its working now, but what I dont get is why was it working without those lines in the first place? its working now so no worries.
    I have a another question for you or anyone else who might be able to advise, with respect to "Teaching a Man to Fish" can you advise the best way for a novice like my self to learn code??

    Thanks

    THE STUDENT

  6. #6
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    The Mystery of Change
    The answer is - it wasn't working without that code. It had been working until you changed something, but you didn't notice when you changed it and it stopped working, you noticed sometime later, after your backup already had the error code in it. That's why I always back up my database after every successful change, sometimes as often as ten times a day. (more often one or two). My backups just have the date on the end of the name, plus a revision letter... MyDB 2013-0611D.mbd would be the fourth (D) backup that day.

    I don't retain those forever - after a month or so I will retain only the final working copy from each day.

    Good Ways to Learn
    1) Access MVP Crystal Long has posted a very good primer on Access, for free, at http://www.accessmvp.com/Strive4Peace/. Start there.

    2) Try to understand what each line is doing.

    3) Decide on a naming convention, and use it. You appear to have several buttons on the same form, which are called
    sav_btn, Command47, Previous, Next, Command26 and Command25

    A convention I'd recommend is to use "cmd" for command button, then one or two short words that describe what it is or does. When a name is made up of multiple words, the first letter of each word should be capitalized. That's called "camel case" because it makes little humps in the words! For example, cmdSave, cmdPrev, cmdNext, cmdWhatButton47Does, cmdWhatButton25Does, etc

    Here's a page describing one familiar naming convention. It's not the one I use, but it's pretty sensible. ANY naming convention is better than NO naming convention. http://www.xoc.net/standards/rvbanc.asp

    Here's a list of reserved words NOT to use as variable or control names http://www.utteraccess.com/forum/Acc...s-t539419.html

    Here's some important words to learn http://www.utteraccess.com/forum/Glo...i-t213518.html

    4) Just keep trying stuff. You will learn things that I don't know, because you will wander into make mistakes that I would never have thought to make. That's a good thing, because we all have slightly different skillsets then and we can help each other.

  7. #7
    THE STUDENT is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2013
    Posts
    11
    Sounds good Dal, I what your saying makes sense, I must admit, i'll take ur advice or how to learn code.

    Thanks Again

    THE STUDENT

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

Similar Threads

  1. Replies: 3
    Last Post: 05-07-2012, 07:57 PM
  2. cascading combo boxes stop working in DAP system
    By James Brazill in forum Forms
    Replies: 5
    Last Post: 06-28-2011, 03:51 AM
  3. Replies: 9
    Last Post: 03-29-2011, 07:08 PM
  4. Navigation Buttons Stop My Code
    By millerdav99 in forum Programming
    Replies: 6
    Last Post: 03-18-2011, 11:13 AM
  5. Replies: 0
    Last Post: 12-20-2010, 12:35 PM

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