难道就将DATA控件改为ADO控件么?再添加如上代码么?
你看,这怎么修改为用ADO打开ACCESS数据库呢?再进行编辑呢?
你看我打算用VB的CMD控制按钮(下一条、上一条、最后一条、第一条、删除。。。),(除了“新增”控件出错外,其余均正常)
再将“新增”按钮的控件代码改下就可以了么?
其代码如下:
Private Sub Command1_Click()
If Command1.Caption = "新增" Then
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command1.Caption = "确定"
Command2.Caption = "放弃"
If Data1.Recordset.RecordCount > 0 Then
Data1.Recordset.MoveLast
End If
Data1.Recordset.AddNew
Data1.Recordset.Update
Text1.SetFocus
Else
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Command1.Caption = "新增"
Command2.Caption = "删除"
Command1.SetFocus
End If
End Sub
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 Command3_Click()
If Data1.Recordset.RecordCount = 0 Then
MsgBox "没有记录!"
Else
If Data1.Recordset.BOF Then
MsgBox "这是第一条记录!"
Data1.Recordset.MoveFirst
Else
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF = True Then
Data1.Recordset.MoveFirst
MsgBox "这是第一条记录!"
End If
End If
End If
End Sub
Private Sub Command4_Click()
If Data1.Recordset.RecordCount = 0 Then
MsgBox "没有记录!"
Else
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
MsgBox "这是最后一条记录!"
Else
Data1.Recordset.MoveNext
If Data1.Recordset.EOF = True Then
Data1.Recordset.MoveLast
MsgBox "这是最后一条记录!"
End If
End If
End If
End Sub
Private Sub Command5_Click()
If Data1.Recordset.RecordCount = 0 Then
MsgBox "没有记录!"
Else
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command6_Click()
If Data1.Recordset.RecordCount = 0 Then
MsgBox "没有记录!"
Else
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Command7_Click()
main.Show
Unload txlqqmc
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
Private Sub Form_Activate()
If Data1.Recordset.RecordCount = 0 Then
Data1.Recordset.AddNew
Data1.Recordset.Update
Else
Data1.Recordset.MoveLast
Data1.Recordset.MoveFirst
End If
End Sub
如何修改呢?
谢谢!