Office中国论坛/Access中国论坛

标题: 请问以下代码为什么错误 [打印本页]

作者: songwl    时间: 2005-3-30 19:56
标题: 请问以下代码为什么错误
'*******模块

Private Sub Workbook_Open()

Sheet1.Cells(3, 7) = Date '加日期

cn.ConnectionString = "provider=sqloledb;server=erp_yx;database=checkdata;user id=123;password=123"

cn.Open



rs.ActiveConnection = cn

rs.CursorLocation = adUseClient

rs.CursorType = adOpenDynamic

rs.LockType = adLockReadOnly

rs.Open "select * from AddPur"



End Sub

'****WORKBOOK

Private Sub Workbook_Open()

Sheet1.Cells(3, 7) = Date '加日期

cn.ConnectionString = "provider=sqloledb;server=erp_yx;database=checkdata;user id=sa;password="

cn.Open



rs.ActiveConnection = cn

rs.CursorLocation = adUseClient

rs.CursorType = adOpenDynamic

rs.LockType = adLockReadOnly

rs.Open "select * from AddPur"



End Sub

'**********按钮

Private Sub 保存_Click()



  Dim i As Integer, j As Integer

  Dim itemCount As Integer, itemNow As Integer

   

  itemCount = 1000

   For i = 5 To itemCount

        rs.AddNew

        rs("ord") = Cells(i, 1)

        rs("part") = Cells(i, 2)

        rs("num") = Cells(i, 3)

        rs("datime") = Cells(i, 4)

        rs("status") = Cells(i, 5)

        rs("docno") = Cells(i, 6)

        rs("note") = Cells(i, 7)

              

        rs.Update

        i = i + 1

    Next i

End Sub



以上代码一运行的时候就出现在rs.AddNew这一行错误,错误原因是:运行错误'3251',当前记录不支持更新,可能是提供程序的限制,也可能是选定锁定类弄的限制.

请问各位是为什么???怎么样修改
作者: 老鬼    时间: 2005-3-30 20:36
rs.LockType = adLockReadOnly '这个你已经设置了只读了,怎么追加?
作者: songwl    时间: 2005-3-30 20:45
哦,谢谢了,我找了半天找不到原因在那




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3