473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help with "Record is Deleted" message

Hello all,

I have an annoying message popping up every time I close a form. Due to performance issues, I am caching data from a linked table on a SQL Server into a temporary local table. The user makes changes to data that are stored in the local table. Then, when the user closes the form, I run a couple of quick queries to update the data back on the server and delete any data in the temp table. After the code runs in the Close event of the form, I get a popup message saying "Record is Deleted" and nothing more. Here is the code from my Form_Close event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. 'Display a form letting the user know that the changes are being saved to the server
  3. DoCmd.OpenForm "Saving_Form", acNormal
  4. [Forms]![Saving_Form].Repaint
  5.  
  6. DoCmd.SetWarnings False
  7. 'Delete all records in the server that need updating
  8. DoCmd.RunSQL "DELETE * FROM [dbo_tblMaintSteps] WHERE [ProspectKey] IN (SELECT [ProspectKey] FROM TEMP_MAINT_STEPS)"
  9. 'append replacement records to the server
  10. DoCmd.RunSQL "INSERT INTO [dbo_tblMaintSteps] SELECT * FROM TEMP_MAINT_STEPS"
  11. 'Delete all records in the temporary table
  12. DoCmd.RunSQL "DELETE * FROM [TEMP_MAINT_STEPS]"
  13. DoCmd.Close acForm, "Saving_Form"
  14. DoCmd.SetWarnings True
  15. End Sub
  16.  
Any suggestions? The error message appears after the last line of code here runs. Even if I keep SetWarnings set to False, I get the error message.
Dec 4 '07 #1
12 13105
puppydogbuddy
1,923 Expert 1GB
Hello all,

I have an annoying message popping up every time I close a form. Due to performance issues, I am caching data from a linked table on a SQL Server into a temporary local table. The user makes changes to data that are stored in the local table. Then, when the user closes the form, I run a couple of quick queries to update the data back on the server and delete any data in the temp table. After the code runs in the Close event of the form, I get a popup message saying "Record is Deleted" and nothing more. Here is the code from my Form_Close event:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2. 'Display a form letting the user know that the changes are being saved to the server
  3. DoCmd.OpenForm "Saving_Form", acNormal
  4. [Forms]![Saving_Form].Repaint
  5.  
  6. DoCmd.SetWarnings False
  7. 'Delete all records in the server that need updating
  8. DoCmd.RunSQL "DELETE * FROM [dbo_tblMaintSteps] WHERE [ProspectKey] IN (SELECT [ProspectKey] FROM TEMP_MAINT_STEPS)"
  9. 'append replacement records to the server
  10. DoCmd.RunSQL "INSERT INTO [dbo_tblMaintSteps] SELECT * FROM TEMP_MAINT_STEPS"
  11. 'Delete all records in the temporary table
  12. DoCmd.RunSQL "DELETE * FROM [TEMP_MAINT_STEPS]"
  13. DoCmd.Close acForm, "Saving_Form"
  14. DoCmd.SetWarnings True
  15. End Sub
  16.  
Any suggestions? The error message appears after the last line of code here runs. Even if I keep SetWarnings set to False, I get the error message.
If this message is related to deleting the Access temporary table, you can try the following:

1. Go to the Access command menu
Select Tools>Options> Edit/Find Tab > uncheck confirm doc deletions
Dec 4 '07 #2
Thanks for the thought, but that doesn't work. What I'm getting is more of an alert than a confirmation. It's a msgbox with the title "Microsoft Office Access." The content is just "Record is deleted." and there is an OK and a help button on it.
Dec 4 '07 #3
puppydogbuddy
1,923 Expert 1GB
Thanks for the thought, but that doesn't work. What I'm getting is more of an alert than a confirmation. It's a msgbox with the title "Microsoft Office Access." The content is just "Record is deleted." and there is an OK and a help button on it.
It is not an alert, otherwise it would be supressed by your Set Warnings code. Based on the message text, I think it is error #3167. If it is, you need to add error handling code to trap/intercept it and display your own custom message.
Dec 4 '07 #4
I tried trapping the error by adding the line
Expand|Select|Wrap|Line Numbers
  1. Msgbox Err.Description
at the end of the close event of the form. The msgbox I created displayed nothing, but I still get that message from Access. Also tried adding
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
at the beginning of the event, but I still get the message from Access. I dont' think I can trap this.

Do you know what executes after the form closes? Is there another event that fires or something? If I put breaks in everyline of the code and step through, the error does not appear until after the last line in this event fires. Interestingly, it makes no difference what that line of code is.
Dec 5 '07 #5
Nathan H
104 100+
I tried trapping the error by adding the line
Expand|Select|Wrap|Line Numbers
  1. Msgbox Err.Description
at the end of the close event of the form. The msgbox I created displayed nothing, but I still get that message from Access. Also tried adding
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
at the beginning of the event, but I still get the message from Access. I dont' think I can trap this.

Do you know what executes after the form closes? Is there another event that fires or something? If I put breaks in everyline of the code and step through, the error does not appear until after the last line in this event fires. Interestingly, it makes no difference what that line of code is.
Could the alert be passed through from the SQL server? Out of my knowledge base, so it may be impossible to work that way, but it has to be coming from somewhere right?
Dec 5 '07 #6
I'm not sure. All work on the SQL server is done on lines 7-10 above
Expand|Select|Wrap|Line Numbers
  1.  'Delete all records in the server that need updating
  2. DoCmd.RunSQL "DELETE * FROM [dbo_tblMaintSteps] WHERE [ProspectKey] IN (SELECT [ProspectKey] FROM TEMP_MAINT_STEPS)"
  3. 'append replacement records to the server
  4. DoCmd.RunSQL "INSERT INTO [dbo_tblMaintSteps] SELECT * FROM TEMP_MAINT_STEPS"
I would think that if the server was going to throw an error it would be after one of those lines runs. The error doesn't come until after the form closes. The record source of the form is the local table - not the table on the server. If I remove the line that deletes the records from the local table
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "DELETE * FROM [TEMP_MAINT_STEPS]"
then I don't get the error. It's almost like the form is trying to save a change to the temporary table after the form closes (maybe)? I really want to leave that line of code in just in case the user has to end task on Access instead of closing out of the form. Then when the user starts the form back up, if there are records in that table, I can give the user the option of restoring the session.
Dec 5 '07 #7
Denburt
1,356 Expert 1GB
It's almost like the form is trying to save a change to the temporary table after the form closes (maybe)? I really want to leave that line of code in just in case the user has to end task on Access instead of closing out of the form. Then when the user starts the form back up, if there are records in that table, I can give the user the option of restoring the session.
It sounds as though you are probably on the right track. Your problem also might be in the following lines if the insert does not complete before the delete runs...

DoCmd.RunSQL "INSERT INTO [dbo_tblMaintSteps] SELECT * FROM TEMP_MAINT_STEPS"
'Delete all records in the temporary table
DoCmd.RunSQL "DELETE * FROM [TEMP_MAINT_STEPS]"

Try adding DBEngine.Idle or DoEvents between the two commands. It could be a possible solution if that is the issue
Dec 5 '07 #8
puppydogbuddy
1,923 Expert 1GB
OK, I think I found out why the error is occurring. It happens because one user deletes a record while the other is using the navigation buttons to move between records, and in the process, passes over the deleted record before the form can be requeried.

You can prevent this error by running Access in exclusive mode. If that is not feasible, you can try the following and see if it works.
Expand|Select|Wrap|Line Numbers
  1. Exit_Continue:
  2. Exit Sub
  3.  
  4. Error_Handler:
  5.     If Err.Number = 3167 Then             'record is deleted error 
  6.     Err.Clear
  7.     Me.Requery    
  8.         Resume Exit_Continue
  9.     Else
  10.         MsgBox "Error# " & Err.Number & " " & Err.Description
  11.         Resume Exit_Continue
  12.     End If
Dec 5 '07 #9
OK, I think I found out why the error is occurring. It happens because one user deletes a record while the other is using the navigation buttons to move between records, and in the process, passes over the deleted record before the form can be requeried.

You can prevent this error by running Access in exclusive mode. If that is not feasible, you can try the following and see if it works.
Expand|Select|Wrap|Line Numbers
  1. Exit_Continue:
  2. Exit Sub
  3.  
  4. Error_Handler:
  5.     If Err.Number = 3167 Then             'record is deleted error 
  6.     Err.Clear
  7.     Me.Requery    
  8.         Resume Exit_Continue
  9.     Else
  10.         MsgBox "Error# " & Err.Number & " " & Err.Description
  11.         Resume Exit_Continue
  12.     End If
I tried trapping the error and the Err object is empty.
Dec 5 '07 #10
puppydogbuddy
1,923 Expert 1GB
Ok, then try this modification to your code :

'Delete all records in the temporary table
DoCmd.RunSQL "DELETE * FROM [TEMP_MAINT_STEPS]"
Me.Requery '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
DoCmd.Close acForm, "Saving_Form"
Dec 5 '07 #11
Nathan H
104 100+
I tried trapping the error and the Err object is empty.

Looking at other threads here, does anything strange happen to the table [TEMP_MAINT_STEPS], like errors in the actual text #error (or something of the sorts) after the code runs?
Dec 5 '07 #12
Ok, then try this modification to your code :

'Delete all records in the temporary table
DoCmd.RunSQL "DELETE * FROM [TEMP_MAINT_STEPS]"
Me.Requery '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
DoCmd.Close acForm, "Saving_Form"
This didn't work, but caused an error to be thrown in a line of code in a subform's current event. Apparently what was happening was that when the main form was closed, the subform's current event hit after the temp table data was deleted. There was a line in that particular subform's current event that saves data in a field. When it tried to save from that subform, the underlying recordsource's data was gone (the temp table) and thus threw the error. Thank you for the suggestion - it helped me trouble shoot where the error was actually coming from! I basically just cleared the source object and link fields in the subform and requeried before running the delete query on the temp table and that solved it. Thanks again.
Dec 5 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: python newbie | last post by:
Hi, I have a wxPython app which dump errors when I close it ( in the debug output at bottom of Komodo, when I close my app. ) Where I got the code for my GUI: Straight from the wxProject.py...
4
by: Tim | last post by:
I have used a graphic 'next record' button on a form. How can I stop it from going past the last existing record? In other words, I don't want it to take the user to a blank record. Thanks Tim
0
by: Mohammad Ali via DotNetMonster.com | last post by:
hi guys, I have a problem with my datagrid. My form is set up so I have two textboxes an add button and an editable datagrid. The datagrid is bound to a datatable which is in my cache.When I...
3
by: vanvee | last post by:
Hi I am trying to program a VB.Net Windows application (in a client server environment with multiple users) and am seeking some help about a possible technique to handle concurreny issues. I am...
3
by: domcatanzarite | last post by:
How would one create a button that on click advances the form to the next "non recurring record" as opposed to the next record. The field the button needs to que from has groups of duplicate...
2
by: Simon | last post by:
Dear reader, Same times a form pops up with the following message "Other user has updated the record" and I can save my update or store it on the clipboard for update later. I am the only...
3
by: Kosmos | last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked...
6
by: Chezza | last post by:
Hi All, Similar to many other posters, I don’t have a lot of experience with access (I'm using access 2003) and know little of VB, although I have picked up a bit while working on this project. ...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.