|
- Private Sub Command2_Click()
- Dim rs As New ADODB.Recordset
- Dim rs1 As New ADODB.Recordset
- Dim rs2 As New ADODB.Recordset
- Dim cnn As New ADODB.Connection
- Dim str As String
- Dim str1 As String
- Dim str2 As String
- Dim x As Double
- Dim y As Double
- Dim curM As Double
- Dim i As Integer
- On Error GoTo Command2_Click_Error
- Set cnn = CurrentProject.Connection
- i = 1
- CurrentDb.Execute "delete * from newtbl"
- Me.Newtbl_子窗体.Requery
- str = "SELECT DISTINCT 记录表.姓名 FROM 记录表"
- rs.Open str, cnn, adOpenKeyset, adLockReadOnly
- Do Until rs.EOF
- y = 50000
- str1 = "SELECT 贷方 FROM 记录表 WHERE 姓名='" & rs.Fields(0) & "' And Not 贷方 Is Null"
- rs1.Open str1, cnn, adOpenKeyset, adLockReadOnly
- x = rs1.Fields(0)
- str2 = "SELECT * FROM Newtbl"
- rs2.Open str2, cnn, adOpenKeyset, adLockOptimistic
- Do Until x <= 0
- If x >= 50000 Then
- curM = y - i
- x = x - y + i
- Else
- curM = x
- x = x - y
- End If
- i = i + 1
- rs2.AddNew
- rs2.Fields(0) = rs.Fields(0)
- rs2.Fields(1) = curM
- rs2.Update
- Loop
- rs2.Close
- rs1.Close
- rs.MoveNext
- Loop
- rs.Close
- Set rs = Nothing
- Set rs1 = Nothing
- Set rs2 = Nothing
- Set cnn = Nothing
- Me.Newtbl_子窗体.Requery
- On Error GoTo 0
- Exit Sub
- Command2_Click_Error:
- MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
- End Sub
复制代码 |
|