|
我先建立一个recordset,然后在表里查找一个记录,用什么命令,seek? findrecord?怎么我都用不对?我的目的是比较两表的内容,有不同的就放到一个新表中。标问号的地方总是通不过? 我不想用不匹配查询
Sub correct_tablle()
'Dim ww As Workspace
Dim db1 As Database
Dim tab1 As dao.Recordset
Dim tab2 As dao.Recordset
Dim tab3 As dao.Recordset
Dim cta00, cta0, cta1, cta2, cta3, cta4, cta5, cta6 As String
Dim ct1a00, ct1a0, ct1a1, ct1a2, ct1a3, ct1a4, ct1a5, ct1a6 As String
Dim retur As Integer
Dim Msg, Style, Title, Help, Ctxt
Msg = "Compare complete!" ' 定义信息。
Style = vbYesNo + vbCritical + vbDefaultButton2 ' 定义按钮。
Title = "MsgBox compare" ' 定义标题。
Help = "DEMO.HLP" ' 定义帮助文件。
Ctxt = 1000 ' 定义标题
' 上下文。
' 显示信息。
'Set ww = DBEngine.Workspaces(0)
Set db1 = CurrentDb
Set tab1 = db1.OpenRecordset("ct")
Set tab2 = db1.OpenRecordset("ct1")
Set tab3 = db1.OpenRecordset("ct2")
tab1.MoveFirst
tab2.MoveFirst
tab3.MoveLast
'ww.BeginTrans
Do Until tab1.EOF
cta00 = tab1!会员编号.value
cta0 = tab1!FRXM.value
cta1 = tab1!ZWMC.value
cta2 = tab1!ZWDZ.value
cta3 = tab1!YZBM.value
cta4 = tab1!DH.value
cta5 = tab1!CZ.value
cta6 = tab1!A24.value
Do Until tab2.EOF
????DoCmd.FindRecord cta00, acAnywhere, True, acDown, False, acCurrent, True
If tab2.EOF Then
tab3.AddNew
tab3!会员编号 = cta00
tab3!ZWMC = cta1
tab3!ct_frxm = cta0
tab3!ct1_frxm = "已删除!"
Else
ct1a0 = tab2!FRXM.value
ct1a1 = tab2!ZWMC.value
ct1a2 = tab2!ZWDZ.value
ct1a3 = tab2!YZBM.value
ct1a4 = tab2!DH.value
ct1a5 = tab2!CZ.value
ct1a6 = tab2!A24.value
If cta0 <> ct1a0 Or cta1 <> ct1a1 Or cta2 <> ct1a2 Or cta3 <> ct1a3 Or cta4 <> ct1a4 Or cta5 <> ct1a5 Or cta6 <> ct1a6 Then
tab3.AddNew
tab3!ct_frxm = cta0
tab3!ct1_frxm = ct1a0
tab3!ct_zwdz = cta2
tab3!ct1_zwdz = ct1a2
tab3!ct_yzbm = cta3
tab3!ct1_yzbm = ct1a3
tab3!ct_dh = cta4
tab3!ct1_dh = ct1a4
tab3!ct_cz = cta5
tab3!ct1_cz = ct1a5
tab3!ct_a24 = cta6
tab3!ct1_a24 = ct1a6
End If
End If
Loop
tab1.MoveNext
Loop
'retur = MsgBox(Msg, Style, Title, Help, Ctxt)
'If retur = vbYes Then ' 用户按下“是”。
' ww.CommitTrans
' 完成某操作。
'Else ' 用户按下“否”。
' ww.Rollback
' 完成某操作。
'End If
tab1.Close
tab2.Close
tab3.Close
End Sub
[em17] |
|