帮助写访问错误。 [英] Help with write access error.

查看:65
本文介绍了帮助写访问错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个带删除按钮的表单。每个记录都存储有列表名称(例如十月或十一月)。列表名称中的每个记录从1到n连续编号。该号码被称为潜在客户号码。我的表单上有一个按钮,用于删除当前记录,然后重新编号共享已删除记录列表名称的记录。问题是,当前记录的潜在客户编号显示在表单上的绑定文本框控件中,因此当我在删除记录后尝试浏览记录时,我收到写入访问错误,告诉我另一个用户已被编辑自上次保存以来的记录。如果我x出错信息,一切都很好。不过,我不希望这条消息出现。我试过操纵文本框的controlsource无济于事。以下是我的代码。请帮忙。


strlist = cbListFilter.Value

iresponse = MsgBox(你确定吗?如果你点击是,那么这个潜在客户的数据将无法恢复!",vbYesNo,"确认删除")

如果iresponse = vbNo则退出Sub

DoCmd.DoMenuItem acFormBar,acEditMenu,8 ,, acMenuVer70

DoCmd.DoMenuItem acFormBar,acEditMenu,6 ,, acMenuVer70

Dim db As DAO.Database

Dim IQrst作为DAO.Recordset

Dim IQstrSQL As String

Dim i As Integer

IQstrSQL =" Select * FROM [PR Only Info] WHERE [List Name] =""" &安培; strlist& """ ORDER BY [潜在客户编号]"

设置db = CurrentDb

设置IQrst = db.OpenRecordset(IQstrSQL,dbOpenDynaset)

IQrst.MoveFirst

i = 1



IQrst.Edit

IQrst![展望数字] = i

IQrst.Update

IQrst.MoveNext

i = i + 1

循环直到IQrst.EOF

IQrst.Close

设置IQrst = Nothing

设置db = Nothing


Exit_Delete_Current_Record_Click:

退出Sub

Err_Delete_Current_Record_Click:

MsgBox"删除失败。

恢复Exit_Delete_Current_Record_Click

解决方案


DoCmd.DoMenuItem acFormBar,acEditMenu,8 ,, acMenuVer70

DoCmd.DoMenuItem acFormBar,acEditMenu,6 ,, acMenuVer70



我认为这一切都取决于这两行代码。

不幸的是,我能找到的关于他们的唯一文件说不要使用这种方法。

你使用参数8& 6这些不在文档中,你没有在你的代码中添加任何注释来解释你想要做什么。

我猜想在任何一个类型的requery之后都需要一个人做删除,但很难确认。


DoCmd.DoMenuItem acFormBar,acEditMenu,8,acMenuVer70

DoCmd.DoMenuItem acFormBar,acEditMenu ,6,acMenuVer70

我从命令按钮向导生成的宏中取出这些代码行来删除记录。有没有更好的方法以编程方式删除当前记录?此外,我已经尝试在窗体和控件本身上进行重新查询,但是我得到了相同的错误消息。上面列出的代码行会根据需要删除记录。问题似乎是在重新编号之后。记录的旧Prospect Number仍显示在文本框中,因此当我移动到另一个记录时,我的表单在文本框中尝试保存的内容与我的VB代码之间存在冲突。


我从命令按钮向导生成的宏中取出这些代码行来删除记录。



这是MS的典型特征。

他们发布的关于如何清楚编码的所有建议,以及应该使用的标准 - 以及他们完全忽略了这些以及他们自己的帮助文件信息。

我很害怕,虽然我可以看看这种代码并发现问题(有时)我在处理过程中不是很有经验代码中的记录集。

我多年前就有过经验,这表明通过代码处理的记录集比简单地执行SQ​​L本身要慢很多倍,所以我尽可能避开。


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

解决方案

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.


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.


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.


这篇关于帮助写访问错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆