|
本帖最后由 wufeng980114 于 2010-2-2 21:18 编辑
我将“表1”查询的数据保存到另一表“表2”中,发现少了最后一条记录,请教各位高手,谢谢了!
Private Sub 确定_Click()
Dim i As Integer
Dim rs, rs2 As ADODB.Recordset
Dim st, st1 As String
If 货物单号 <> "" Then
Call ClearQY '调用清空程序,将表2的数据清空
Set rs = New ADODB.Recordset
st = "select * from 表1 where 货物单号 = '" & Me.货物单号 & "'"
rs.Open st, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
rs.MoveFirst
Set rs2 = New ADODB.Recordset
st2 = "select * from 表2 "
rs2.Open st2, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
For i = 1 To rs.RecordCount
rs2.AddNew
rs2("货物单号") = rs("货物单号")
rs2("姓名") = rs("姓名")
rs2("货物") = rs("货物")
Me.货物显示.Requery
rs.MoveNext
Next i
Else
End If
Set rs = Nothing
Set rs2 = Nothing
End Sub
Private Sub ClearQY()
Dim g As Integer
Dim QYrs As ADODB.Recordset
Dim QYst As String
Set QYrs = New ADODB.Recordset
QYst = "select * from 表2 "
QYrs.Open QYst, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
If QYrs.RecordCount <> 0 Then
QYrs.MoveFirst
For g = 1 To QYrs.RecordCount
QYrs.Delete 1
QYrs.MoveNext
Next g
' QYrs.Update
Else
End If
Set QYrs = Nothing
QYst = ""
End Sub |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|