我做的通讯录小程序中,删除代码能够成功运行!
但我的数据更新程序代码不行,失败了!只能在ACCESS里修改更新!
删除代码如下:
Private Sub Command2_Click()
Dim str1
If Command2.Caption = "放弃" Then
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Command1.Caption = "新增"
Command2.Caption = "删除"
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
Text10.Enabled = False
Text11.Enabled = False
Text12.Enabled = False
Text13.Enabled = False
Text14.Enabled = False
Text15.Enabled = False
Else
If Data1.Recordset.RecordCount = 0 Then
MsgBox "没有记录!", 32, "注意"
Exit Sub
Else
str1 = MsgBox("删除该记录么?", 17, "删除")
If str1 = 1 Then
Data1.Recordset.Delete
Data1.Refresh
If Data1.Recordset.RecordCount = 0 Then
MsgBox "记录数为零!"
Data1.Recordset.AddNew
End If
End If
End If
End If
End Sub
数据更新代码如下:
Private Sub Data1_Validate(Action As Integer, Save As Integer)
Static addrecord As Boolean
Dim msg
Select Case Action
Case 1, 2, 3, 4, 5, 11
If Save Then
msg = MsgBox("数据需要更新么?", vbYesNo)
If msg = vbNo Then
Save = 0
If addrecord Then
Data1.UpdateControls
End If
End If
End If
If Action = 5 Then addrecord = True Else addrecord = False
Command2.Enabled = True
End Select
End Sub
我打算把删除代码里的:“Data1.Recordset.AddNew
”也添加到更新代码的相应位置里:
如下:
Case 1, 2, 3, 4, 5, 11
If Save Then
msg = MsgBox("数据需要更新么?", vbYesNo)
If msg = vbNo Then
Save = 0
If addrecord Then
Data1.UpdateControls
Data1.Recordset.AddNew
End If
End If
End If
但还是不行!
请帮我查看一下!谢谢!