handle error in save button because of (docmd.Requery)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mseo
    New Member
    • Oct 2009
    • 183

    #16
    the version of microsoft access is 2003

    Comment

    • mseo
      New Member
      • Oct 2009
      • 183

      #17
      hi,
      this code for save button for handling the 3021 error and any other error which happen during the save action

      Code:
      Private Sub Save_Click()
      On Error GoTo Err_Save_Click
          DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
      Exit_Save_Click:
          Exit Sub
      Err_Save_Click:
          MsgBox Err.Description, vbDefaultButton1 + vbCritical + vbOKOnly, "Hi-Tech SysAdmin"
          Resume Exit_Save_Click
      End Sub
      but when I click save the command excutes the save command but I need to set the form to new record after saving the previous one but using the same code
      the second question is how can attach ms-access in here?
      thank you

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #18
        something like

        [code=vba]
        DoCmd.gotoRecor d acNewRecord
        [/code]

        which would also save any unsaved changes to the current record before moving on to the new record....if memory serves me correctly

        Comment

        • topher23
          Recognized Expert New Member
          • Oct 2008
          • 234

          #19
          Delerna's almost got it. In specific, its

          Code:
          DoCmd.GoToRecord , , acNewRec
          However, you can find that easily in the help file, or as an answer on countless threads spread across the Internet. Really, it would be so much better for you, mseo, if you'd look for the answer yourself before posting it up as a question.

          Comment

          • topher23
            Recognized Expert New Member
            • Oct 2008
            • 234

            #20
            As for the second question about attaching your database, see these guidelines by NeoPa, then click "Manage Attachments" in the "Additional Options" section of the advanced reply page. From there, you should be able to handle it.
            Originally posted by NeoPa
            When attaching your work please follow the following steps first :

            1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
            2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
            3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
            4. If you've done anything in steps 1 to 3 then make sure that the problem you're experiencing is still evident in the updated version.
            5. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
            6. Compact the database.
            7. Compress the database into a ZIP file.
            8. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.

            It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.
            Last edited by topher23; Nov 4 '09, 09:59 PM. Reason: The quote came out funny. Had to sort of fix it.

            Comment

            • mseo
              New Member
              • Oct 2009
              • 183

              #21
              hi, the problem is not about saving the uncurrent changes before moving to new record but it is all about how to move to the next record, excuse me because this code must be included within the previous code I posted and I really tried this code
              Code:
              docmd.gotorecord,, acrec
              and nothing changed the same thing appears for me the save record in unavailable error number 3046
              and I didn't mean to tease anyone but I am in real problem so I want attach the database form to see the real problem yourselves.
              thanks

              Comment

              • mseo
                New Member
                • Oct 2009
                • 183

                #22
                hi,
                I attached the form which I have the problem with
                please try to help me handling it
                thanks

                Comment

                • topher23
                  Recognized Expert New Member
                  • Oct 2008
                  • 234

                  #23
                  Okay, this code works in the OnClick event of your save button without issue. I added 3 different Star Wars characters in a row with it.

                  Code:
                  Private Sub Save_Click()
                  On Error GoTo Err_Save_Click
                      DoCmd.RunCommand acCmdSaveRecord
                      DoCmd.GoToRecord , , acNewRec
                  Exit_Save_Click:
                      Exit Sub
                  Err_Save_Click:
                      MsgBox Err.Description
                      Resume Exit_Save_Click
                  End Sub
                  Also, your "Close" button is hiding behind the tab control. As soon as you click on a text box, you lose the button, but if you click where it "should" be, it closes the form. To fix this, open the form in design view, selec the Close button and go to Format > Move To Front on the Menu bar.

                  Let us know if you have more issues.
                  Last edited by topher23; Nov 4 '09, 11:12 PM. Reason: clarification

                  Comment

                  • topher23
                    Recognized Expert New Member
                    • Oct 2008
                    • 234

                    #24
                    Slight modification to the code. This makes it so that when the update is cancelled because the user didn't type in everything, it doesn't give them a "RunCommand has been cancelled." dialog box by telling the error handler not to display anything when that specific error code pops up.

                    Code:
                    Private Sub Save_Click()
                    On Error GoTo Err_Save_Click
                        DoCmd.RunCommand acCmdSaveRecord
                        DoCmd.GoToRecord , , acNewRec
                    Exit_Save_Click:
                        Exit Sub
                    Err_Save_Click:
                        Select Case Err
                        Case 2046, 2501
                            'do nothing
                        Case Else
                            MsgBox Err & ", " & Err.Description
                        End Select
                        Resume Exit_Save_Click
                    End Sub

                    Comment

                    • mseo
                      New Member
                      • Oct 2009
                      • 183

                      #25
                      thanks topher23 for your answer it is the really best answer
                      but I get error msg for error 3021

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32645

                        #26
                        Mseo - Please check your PMs.

                        I need a confirmation of receipt from you when you've read it please.

                        Comment

                        • topher23
                          Recognized Expert New Member
                          • Oct 2008
                          • 234

                          #27
                          I spent a bit more time with your form, and the only way was able to replicate a 3021 error was when I tried to save the record without filling out all of the required fields.

                          If an error is being generated and you know you can just ignore it because it's not really an error, add it to the Case statement from the last post:

                          Originally posted by topher23
                          Code:
                              Case 2046, 2501
                          So it looks like

                          Code:
                              Case 2046, 2501, 3021
                          The only problem with this is that sometimes you might ignore a legitimate error, so it's best to make sure that the only way that specific error is generated is in a way that is safe to be ignored.

                          Comment

                          Working...