Dim t, ts t = 0 ts = 0 Set cnn1 = New ADODB.Connection cnn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\123.MDB;" cnn1.ConnectionTimeout = 5 cnn1.Open sqlstr = "SELECT * from zu ;" sqlasd = "SELECT * from zi;" Set rs1 = New ADODB.Recordset Set rs2 = New ADODB.Recordset Set rs3 = New ADODB.Recordset Set rs4 = New ADODB.Recordset rs1.Open sqlstr, cnn1, adOpenKeyset, adLockOptimistic rs2.Open sqlasd, cnn1, adOpenKeyset, adLockOptimistic rs1.AddNew rs1.Fields("编号") = Range("d1") rs1.Fields("主表名称") = Range("d2") rs1.MoveLast rs1.Update Range("d1") = rs1.Fields("编号") Range("d2") = rs1.Fields("主表名称") sqlasdas = "Delete from zi where 编号='" & Range("d1") & "';" rs3.Open sqlasdas, cnn1, adOpenKeyset, adLockOptimistic Range("d10").Select Do While ActiveCell <> "" rs2.AddNew rs2.Fields("编号") = Range("d1") rs2.Fields("子表名称") = ActiveCell rs2.MoveLast rs2.Update ActiveCell.Offset(1, 0).Select Loop rs2.Requery If rs2.RecordCount > 0 Then rs2.MoveFirst End If sqlasdas = "SELECT * from zi where 编号='" & Range("d1") & "';" rs4.Open sqlasdas, cnn1, adOpenKeyset, adLockOptimistic Range("A10:z8000").ClearContents Do While rs4.EOF <> True Cells(10 + ts, 4) = rs4.Fields("子表名称") rs4.MoveNext ts = ts + 1 Loop |