Option Compare Database PrivateSub CmdDelete_Click() Call DeleteOldData(Me.Text0) End Sub Function DeleteOldData(YearStr) Dim Sql, Sqlo, Sqlm Dim Rst As DAO.Recordset Dim i IfIsNull(YearStr) Then Sql ="Select ItemNo From ProdutsInfo Where YearS Is Null" Else Sql ="Select ItemNo From ProdutsInfo Where YearS='"& YearStr &"相片'" EndIf Me.Text4 =0 Set Rst = CurrentDb.OpenRecordset(Sql) IfNot (Rst.EOF And Rst.BOF) Then Rst.MoveLast Rst.MoveFirst Me.Text4 = Rst.RecordCount For i =1To Me.Text4 Me.LB.Caption = i &" 删除记录:"& Rst("ItemNo").Value Me.Repaint Sqlo ="Delete * From Others Where ItemNo='"& Rst("ItemNo").Value &"'" CurrentDb.Execute Sqlo Sqlm ="Delete * From Materials Where ItemNo='"& Rst("ItemNo").Value &"'" CurrentDb.Execute Sqlm Rst.MoveNext Next Me.LB.Caption ="删除明细记录完毕." EndIf IfIsNull(YearStr) Then Sql ="Delete ItemNo From ProdutsInfo Where YearS Is Null" Else Sql ="Delete ItemNo From ProdutsInfo Where YearS='"& YearStr &"相片'" EndIf CurrentDb.Execute (Sql) Me.LB.Caption ="删除货号记录完毕." End Function PrivateSub CmdDeletMx_Click() Dim Sql Dim Rst As DAO.Recordset Me.LBOther.Caption ="删除明细内容操作:" IfNotIsNull(Me.TBoxOther) Then Sql ="Delete * From Others Where ItemNo='"& Me.TBoxOther &"'" CurrentDb.Execute Sql Sql ="Delete * From Materials Where ItemNo='"& Me.TBoxOther &"'" CurrentDb.Execute Sql Me.LBOther.Caption ="删除成功." Else Me.LBOther.Caption ="删除失败...." EndIf End Sub PrivateSub CmdQry_Click() Call Qry(Me.Text0) End Sub Function Qry(YearStr) Dim Sql Dim Rst As DAO.Recordset Dim i IfIsNull(YearStr) Then Sql ="Select ItemNo From ProdutsInfo Where YearS Is Null" Else Sql ="Select ItemNo From ProdutsInfo Where YearS='"& YearStr &"相片'" EndIf Me.Text4 =0 Set Rst = CurrentDb.OpenRecordset(Sql) IfNot (Rst.EOF And Rst.BOF) Then Rst.MoveLast Rst.MoveFirst Me.Text4 = Rst.RecordCount EndIf End Function