the version of microsoft access is 2003
handle error in save button because of (docmd.Requery)
Collapse
X
-
hi,
this code for save button for handling the 3021 error and any other error which happen during the save action
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 codeCode: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
the second question is how can attach ms-access in here?
thank youComment
-
Delerna's almost got it. In specific, its
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.Code:DoCmd.GoToRecord , , acNewRec
Comment
-
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.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
-
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 codeand nothing changed the same thing appears for me the save record in unavailable error number 3046Code:docmd.gotorecord,, acrec
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.
thanksComment
-
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.
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.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
Let us know if you have more issues.Comment
-
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 SubComment
-
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:
So it looks like
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.Code:Case 2046, 2501, 3021
Comment
Comment