ADO新记录#Error为什么?? [英] ADO new record #Error why??
问题描述
Hello Everyone
我有一个主表单(frmNewOrder)和一个子表单(SubOrderBeneficiary)。
在主表单上我有一个按钮将子表单
(SubOrderBeneficiary)发送到新记录。当我按下按钮时,一切正常,期待
,当从当前记录改变时,子窗体上的控件显示#Error
几分之一秒
表示新记录并且一切正常。
有谁知道如何防止这种情况因为看起来不好
专业人士?
我使用的代码如下:
私有子cmdNewBene_Click()
出错GoTo Err_cmdNewBene_Click
Dim cn As ADODB.Connection
Dim rs as ADODB.Recordset
设置cn = CurrentProject .AccessConnection
设置rs =新ADODB.Recordset
设置SubBen = Me.SubOrderBeneficiary.Form
使用rs
Set .ActiveConnection = cn
.Source =" SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
''''"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
。打开
结束
设置SubBen.Recordset = rs
设置rs = Nothing
设置cn = Nothing
Me.SubOrderBeneficiary.SetFocus
Exit_cmdNewBene_Click:
退出Sub
Err_cmdNewBene_Click:
MsgBox"您的请求无法处理。 Err 14 - &
Err.Description& Err.Number,vbCritical,错误
恢复退出_cmdNewBene_Click
结束子
任何评论和可能的解决方案都会对我有所帮助。
先谢谢。
GAVO。
Hello Everyone
I have a main form (frmNewOrder) and a sub form (SubOrderBeneficiary).
On the main form I have a button which sends the Subform
(SubOrderBeneficiary) to a newrecord. Everything works fine expect that
when I press the button, the controls on the subform display an #Error
for a fraction of a second when changing from the current record on the
subform to the new record and theneverything works fine.
Does anyone knows how can I prevent this as it does not look
professional?
The code Im using is as follows:
Private Sub cmdNewBene_Click()
On Error GoTo Err_cmdNewBene_Click
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
Set SubBen = Me.SubOrderBeneficiary.Form
With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
''''"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
Set SubBen.Recordset = rs
Set rs = Nothing
Set cn = Nothing
Me.SubOrderBeneficiary.SetFocus
Exit_cmdNewBene_Click:
Exit Sub
Err_cmdNewBene_Click:
MsgBox "Your request could not be processed. Err 14 - " &
Err.Description & Err.Number, vbCritical, "Error"
Resume Exit_cmdNewBene_Click
End Sub
Any comments and possible solution would help me a lot.
Thanks in advanced.
GAVO.
推荐答案
GAVO-UK写道:
GAVO-UK wrote:
大家好我
我有一个主表单(frmNewOrder)和一个子表单(SubOrderBeneficiary)。
主要表单我有一个按钮,将子表单(SubOrderBeneficiary)发送到新记录。一切正常,期待
当我按下按钮时,子窗体上的控件在从
子窗体上的当前记录更改为新的时间后显示#Error
几分之一秒记录和一切正常。
有谁知道我怎么能防止这个因为它看起来不专业?
我使用的代码如下:<私有子cmdNewBene_Click()
错误GoTo Err_cmdNewBene_Click
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
设置cn = CurrentProject.AccessConnection
设置rs =新ADODB.Recordset
设置SubBen = Me.SubOrderBeneficiary.Form
设置rs
设置.ActiveConnection = cn
.Source =" SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
''''"
。LockType = adLockOptimistic
.CursorType = adOpenKeyset
。打开
结束
设置SubBen.Recordset = rs
设置rs = Nothing
设置cn = Nothing
Me.SubOrderBeneficiary.SetFocus
Exit_cmdNewBene_Click:
退出Sub
Err_cmdNewBene_Click:
MsgBox"您的请求无法处理。 Err 14 - &
Err.Description& Err.Number,vbCritical,Error
Resume Exit_cmdNewBene_Click
End Sub
任何评论和可能的解决方案都会对我有所帮助。
谢谢高级。
GAVO。
Hello Everyone
I have a main form (frmNewOrder) and a sub form (SubOrderBeneficiary).
On the main form I have a button which sends the Subform
(SubOrderBeneficiary) to a newrecord. Everything works fine expect that
when I press the button, the controls on the subform display an #Error
for a fraction of a second when changing from the current record on the
subform to the new record and theneverything works fine.
Does anyone knows how can I prevent this as it does not look
professional?
The code Im using is as follows:
Private Sub cmdNewBene_Click()
On Error GoTo Err_cmdNewBene_Click
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn = CurrentProject.AccessConnection
Set rs = New ADODB.Recordset
Set SubBen = Me.SubOrderBeneficiary.Form
With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM tblBeneficiary WHERE BeneficiaryID =
''''"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
Set SubBen.Recordset = rs
Set rs = Nothing
Set cn = Nothing
Me.SubOrderBeneficiary.SetFocus
Exit_cmdNewBene_Click:
Exit Sub
Err_cmdNewBene_Click:
MsgBox "Your request could not be processed. Err 14 - " &
Err.Description & Err.Number, vbCritical, "Error"
Resume Exit_cmdNewBene_Click
End Sub
Any comments and possible solution would help me a lot.
Thanks in advanced.
GAVO.
你能做这样的事吗?在主窗体中创建一个按钮,其中
代码类似于
Me.SubFormName.SetFocus
DoCmd.GoToRecord acActiveDataObject ,, acNewRec >
您的代码确实将子表单发送到新记录,并且不显示#B
,但它不允许我编辑新记录。
其他任何可能的解决方案?
谢谢
GAVO。
Your code does send the subform to a new record and does not display
the #Error, but it does not allow me to EDIT the new record.
Any other possible solutions?
Thanks
GAVO.
GAVO-UK写道:
GAVO-UK wrote:
您的代码确实将子表单发送到新记录并且不显示#Error,但它不允许我编辑新记录。
任何其他可能的解决方案?
GAVO。
Your code does send the subform to a new record and does not display
the #Error, but it does not allow me to EDIT the new record.
Any other possible solutions?
Thanks
GAVO.
你有AllowEdits设置为true吗?表格的记录来源是否可以更新
?
Do you have AllowEdits set to true? Is your recordsource for the form
updateable?
这篇关于ADO新记录#Error为什么??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!