今天早上写的一个简单窗体,删除关系表中的旧数据。没有对非法数据的处理。界面如下:

下面是代码:呵呵。
Option Compare Database
Private Sub CmdDelete_Click()
Call DeleteOldData(Me.Text0)
End Sub
Function DeleteOldData(YearStr)
Dim Sql, Sqlo, Sqlm
Dim Rst As DAO.Recordset
Dim i
If IsNull(YearStr) Then
Sql = "Select ItemNo From ProdutsInfo Where YearS Is Null"
Else
Sql = "Select ItemNo From ProdutsInfo Where YearS='" & YearStr & "相片'"
End If
Me.Text4 = 0
Set Rst = CurrentDb.OpenRecordset(Sql)
If Not (Rst.EOF And Rst.BOF) Then
Rst.MoveLast
Rst.MoveFirst
Me.Text4 = Rst.RecordCount
For i = 1 To 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 = "删除明细记录完毕."
End If
If IsNull(YearStr) Then
Sql = "Delete ItemNo From ProdutsInfo Where YearS Is Null"
Else
Sql = "Delete ItemNo From ProdutsInfo Where YearS='" & YearStr & "相片'"
End If
CurrentDb.Execute (Sql)
Me.LB.Caption = "删除货号记录完毕."
End Function
Private Sub CmdDeletMx_Click()
Dim Sql
Dim Rst As DAO.Recordset
Me.LBOther.Caption = "删除明细内容操作:"
If Not IsNull(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 = "删除失败...."
End If
End Sub
Private Sub CmdQry_Click()
Call Qry(Me.Text0)
End Sub
Function Qry(YearStr)
Dim Sql
Dim Rst As DAO.Recordset
Dim i
If IsNull(YearStr) Then
Sql = "Select ItemNo From ProdutsInfo Where YearS Is Null"
Else
Sql = "Select ItemNo From ProdutsInfo Where YearS='" & YearStr & "相片'"
End If
Me.Text4 = 0
Set Rst = CurrentDb.OpenRecordset(Sql)
If Not (Rst.EOF And Rst.BOF) Then
Rst.MoveLast
Rst.MoveFirst
Me.Text4 = Rst.RecordCount
End If
End Function

本文介绍了一个简单的窗体应用程序,用于删除关系表中的旧数据。该应用能够根据指定年份或空值条件查询并删除主表及关联表中的对应记录。
1093

被折叠的 条评论
为什么被折叠?



