Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

recordset如何在不同的控件中定位同一个记录?

Foxproboy  发表于:2016-02-02 22:54:12  
复制

请教各位大侠:

我现在文本框更新过程中通过ADODB   定义了2个数据集rst和rst1并打开数据表,想在另一个按钮的点击过程里将定位到记录追加到另一个表中。

但是系统执行到点击过程的“rst1.addnew”时系统出现错误:“Run-time error 424: 'object required'   ”

啥原因?

1. 文本框更新过程

Private Sub t2_AfterUpdate()
Dim rst,rst1 As ADODB.Recordset '
Dim strsql, strsql1 As String '
strsql = "select * from Spareparts"
strsql1 = "select * from SInbound"
Set rst = New ADODB.Recordset
Set rst1 = New ADODB.Recordset
rst.Open strsql, CurrentProject.Connection, adOpenKeyset,  adLockOptimistic
rst1.Open strsql1, CurrentProject.Connection, adOpenKeyset,  adLockOptimistic

Do While Not rst.EOF
If Me.t2.Value = rst!StockNo.Value Then

For i = 3 To 18
Me("t" & i).Enabled = True
Next

Me.t3.Value = rst!Name.Value
Me.t4.Value = rst!CriticalCls.Value
'Me.T5.Value = rst!Birthday.Value
Me.t6.Value = rst!specification.Value
Me.t7.Value = rst!PartNo.Value
Me.t8.Value = rst!ArtNo.Value
Me.t9.Value = rst!Brand.Value
Me.t10.Value = rst!manufacturer.Value
'Me.t11.Value = rst!Shoesize.Value
Me.t12.Value = rst!Subprice3.Value
'Me.t13.Value = rst!Weight.Value
Me.t14.Value = rst!safetystock.Value
Me.t15.Value = rst!Onstock.Value
Me.t16.Value = rst!shelvesNo.Value
Me.t17.Value = rst!Purpose.Value
Me.t18.Value = rst!Remark.Value
Exit Do

Else
rst.MoveNext
End If
Loop

If rst.EOF Then

For i = 3 To 18
Me("t" & i).Value = Null
Me("t" & i).Enabled = True
Next

MsgBox "this's a new material!"

End If

End Sub

2. 新增记录点击过程

Private Sub Command48_Click()

rst1.AddNew

rst1!IBdate.Value = Me.T1.Value
rst1!StockNo.Value = Me.t2.Value
rst1!Name.Value = Me.t3.Value
rst1!CriticalCls.Value = Me.t4.Value
rst1!pono.Value = Me.T5.Value
rst1!specification.Value = Me.t6.Value
rst1!PartNo.Value = Me.t7.Value
rst1!ArtNo.Value = Me.t8.Value
rst1!Brand.Value = Me.t9.Value
rst1!manufacturer.Value = Me.t10.Value
rst1!DeliveryTime.Value = Me.t11.Value
rst1!Price.Value = Me.t12.Value
rst1!Inbound.Value = Me.t13.Value
rst1!safetystock.Value = Me.t14.Value
rst1!shelvesNo.Value = Me.t16.Value
rst1!Purpose.Value = Me.t17.Value
rst1!IRemark.Value = Me.t18.Value

rst1.Update
rst1.Close
Set rst1 = Nothing
MsgBox Me.t2.Value & "records is done!"

For i = 3 To 18
Me("t" & i).Value = Null
Me("t" & i).Enabled = False
Next

End Sub

 

Top
煮江品茶 发表于:2016-02-03 09:58:51
删除冗余的字段即可

总记录:1篇  页次:1/1 9 1 :