473,396 Members | 1,768 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,396 software developers and data experts.

Help with write access error.

Hi,

I have a form with a delete button. Each record is stored with a list name (e.g. "October" or "November"). Each record within a list name is consecutively numbered from 1 to n. This number is called the "prospect number" I have a button on my form that deletes the current record and then renumbers the records that share the deleted record's list name. The problem is, the current record's prospect number is displayed in a bound textbox control on the form, so when I attempt to navigate through the records after deleting one, I get the Write-access error that tells me another user is edited the record since it was last saved. If I "x" out of the error message, everything is fine. I don't want the message to appear, though. I have tried manipulating the controlsource of the textbox to no avail. Below is my code. Please help.

strlist = cbListFilter.Value
iresponse = MsgBox("Are you sure? If you click yes, data for this prospect will be unrecoverable!", vbYesNo, "Confirm Delete")
If iresponse = vbNo Then Exit Sub
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Dim db As DAO.Database
Dim IQrst As DAO.Recordset
Dim IQstrSQL As String
Dim i As Integer
IQstrSQL = "Select * FROM [PR Only Info] WHERE[List Name] = """ & strlist & """ ORDER BY [Prospect Number]"
Set db = CurrentDb
Set IQrst = db.OpenRecordset(IQstrSQL, dbOpenDynaset)
IQrst.MoveFirst
i = 1
Do
IQrst.Edit
IQrst![Prospect Number] = i
IQrst.Update
IQrst.MoveNext
i = i + 1
Loop Until IQrst.EOF
IQrst.Close
Set IQrst = Nothing
Set db = Nothing

Exit_Delete_Current_Record_Click:
Exit Sub
Err_Delete_Current_Record_Click:
MsgBox "Deletion was not successful."
Resume Exit_Delete_Current_Record_Click
Nov 14 '06 #1
10 6560
NeoPa
32,556 Expert Mod 16PB
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
I think this all hinges on the two lines of code here.
Unfortunately, the only documentation I can find about them says don't use this method.
You use parameters 8 & 6 which are not in the documentation, and you haven't put any comments in your code to explain what you're trying to do.
I would guess some type of requery is required after whichever one does the delete, but it's hard to confirm.
Nov 14 '06 #2
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

I took these lines of code out of a macro generated by the command button wizard for deleting records. Is there a better way to delete the current record programatically? Also, I've tried doing a requery on the form and the control itself, but I get the same error message. The lines of code listed above do delete the record as desired. The problem seems to be after the renumbering. The record's old Prospect Number is still displayed in the textbox, so when I move to a different record, there is a conflict between what my form is trying to save in the text box and what my VB code did.
Nov 15 '06 #3
NeoPa
32,556 Expert Mod 16PB
I took these lines of code out of a macro generated by the command button wizard for deleting records.
That is so typical of MS.
All the recommendations they publish of how to code clearly, and standards that should be used - and they completely ignore that and their own help file info.
I'm afraid, while I can look at this sort of code and spot problems (sometimes) I'm not very experienced in processing through recordsets in code.
I had experience many years ago now, that indicated recordsets processed via code ran many many times more slowly than simply executing the SQL itself, so I steer clear when I can.
Nov 15 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
You could try putting in On Error Continue somewhere in the loop to catch the error. You could also try a DoEvents command to see if this will solve the problem. If either of these don't solve the problem let me know and I'll look at it again.

Do
On Error Continue
IQrst.Edit
IQrst![Prospect Number] = i
IQrst.Update
DoEvents
IQrst.MoveNext
On Error Continue
i = i + 1
Loop Until IQrst.EOF
Nov 15 '06 #5
Thanks, but this part of the code is working correctly and I'm already trapping errors on this sub. The problem is after the code runs. The code runs and everything is fine. The deleted record is gone from the table and form. However, once the record is deleted, the record that now shows in my form is showing its OLD prospect number. Thus, when I try to move off this record with the form, I get the write conflict error. It's trying to save the number in the textbox (which is the old number) when the recordset has already been modified. I thought a refresh or requery should do the trick but it doesn't.
Nov 15 '06 #6
MMcCarthy
14,534 Expert Mod 8TB
Thanks, but this part of the code is working correctly and I'm already trapping errors on this sub. The problem is after the code runs. The code runs and everything is fine. The deleted record is gone from the table and form. However, once the record is deleted, the record that now shows in my form is showing its OLD prospect number. Thus, when I try to move off this record with the form, I get the write conflict error. It's trying to save the number in the textbox (which is the old number) when the recordset has already been modified. I thought a refresh or requery should do the trick but it doesn't.
What is the control source of the ProspectNumber
Nov 15 '06 #7
The control source of that text box is the field that was updated when the delete/renumber code ran. I tried setting it to "" before the renumbering and then resetting it to [Prospect Number] after the renumbering but that didn't work either.
Nov 15 '06 #8
MMcCarthy
14,534 Expert Mod 8TB
The control source of that text box is the field that was updated when the delete/renumber code ran. I tried setting it to "" before the renumbering and then resetting it to [Prospect Number] after the renumbering but that didn't work either.
Run a save before opening the recordset. If that doesn't work put Me.Requery in the same spot. The problem I think you're having is you're trying to open a recordset before the change is committed.

If either of these doesn't work let me know as there are some other things we could try.


strlist = cbListFilter.Value
iresponse = MsgBox("Are you sure? If you click yes, data for this prospect will be unrecoverable!", vbYesNo, "Confirm Delete")
If iresponse = vbNo Then Exit Sub
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim db As DAO.Database
Dim IQrst As DAO.Recordset
Dim IQstrSQL As String
Dim i As Integer
IQstrSQL = "Select * FROM [PR Only Info] WHERE[List Name] = """ & strlist & """ ORDER BY [Prospect Number]"
Set db = CurrentDb
Set IQrst = db.OpenRecordset(IQstrSQL, dbOpenDynaset)
IQrst.MoveFirst
i = 1
Do
IQrst.Edit
IQrst![Prospect Number] = i
IQrst.Update
IQrst.MoveNext
i = i + 1
Loop Until IQrst.EOF
IQrst.Close
Set IQrst = Nothing
Set db = Nothing

Exit_Delete_Current_Record_Click:
Exit Sub
Err_Delete_Current_Record_Click:
MsgBox "Deletion was not successful."
Resume Exit_Delete_Current_Record_Click
Nov 15 '06 #9
Beautiful! thanks!
Nov 15 '06 #10
MMcCarthy
14,534 Expert Mod 8TB
Beautiful! thanks!
No problem.

Glad it worked.
Nov 15 '06 #11

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

Similar topics

4
by: StumpY | last post by:
Hi I am trying to append information collected from a form into a text file (already created and currently in the root of my web) on my ISP's webserver. The code snippet causing the problem is;...
8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: MyndPhlyp | last post by:
I am about to completely lose what is left of my poor mynd! The historical dissertation gets rather verbose, so I hope you can wade through it all. I really need some help on this one or I'm...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
1
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
1
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I...
4
by: Brad Isaacs | last post by:
I am working with ASP.NET 2.0 and using an SQL Server 2000 database. I am using Visual Studio 2005 and developing on my Local machine. I am working with Login controls ASP.Configuration, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.