Public Sub initial_button()
If Data1.Recordset.RecordCount = 0 Then
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = True
Command4.Enabled = False
Command5.Enabled = True
Command6.Enabled = False
Else
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
Command6.Enabled = True
End If
End Sub
Public Sub savecancel()
Command6.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = False
End Sub
Private Sub Command1_Click()
Dim i As Integer
On Error GoTo errdel:
Data1.Recordset.AddNew
For i = 0 To 3
Text1(i).Text = ""
Next
savecancel
Exit Sub
errdel:
MsgBox Err.Description
End SubPrivate Sub Command2_Click()
On Error GoTo delerr
Dim s As String
s = MsgBox("确定要删除这组记录吗?", vbQuestion + vbOKCancel, "删除确定")
If s = 1 Then
BeginTrans
Data1.Recordset.Delete
CommitTrans
Data1.Recordset.MoveNext
If Data1.Recordset.RecordCount > 0 Then
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End If
End If
Exit Sub
delerr:
Rollback
MsgBox Err.Description
End SubPrivate Sub Command3_Click()
Dim position As Variant
Dim s As String
On Error GoTo updateerr
BeginTrans
Data1.Recordset.Update
CommitTrans
initial_button
Data1.Refresh
Exit Sub
updateerr:
Rollback
MsgBox Err.Description
End SubPrivate Sub Command4_Click()
On Error GoTo cancelerr
Data1.Recordset.CancelUpdate
initial_button
Exit Sub
cancelerr:
MsgBox Err.Description
End SubPrivate Sub Command5_Click()
Unload Me
End SubPrivate Sub Command6_Click()
Dim mynumber As String
mynumber = InputBox$("请输入学号(6位)", "学号搜索", "830001")
If mynumber = "学号='" & mynumber & "'" Then
Data1.Recordset.FindFirst mynumber
End If
End SubPrivate Sub Form_activate()
initial_button
End Sub添加时,操作怎么会提示被关联对象取消,无法保存啊
If Data1.Recordset.RecordCount = 0 Then
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = True
Command4.Enabled = False
Command5.Enabled = True
Command6.Enabled = False
Else
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = True
Command6.Enabled = True
End If
End Sub
Public Sub savecancel()
Command6.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = False
End Sub
Private Sub Command1_Click()
Dim i As Integer
On Error GoTo errdel:
Data1.Recordset.AddNew
For i = 0 To 3
Text1(i).Text = ""
Next
savecancel
Exit Sub
errdel:
MsgBox Err.Description
End SubPrivate Sub Command2_Click()
On Error GoTo delerr
Dim s As String
s = MsgBox("确定要删除这组记录吗?", vbQuestion + vbOKCancel, "删除确定")
If s = 1 Then
BeginTrans
Data1.Recordset.Delete
CommitTrans
Data1.Recordset.MoveNext
If Data1.Recordset.RecordCount > 0 Then
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End If
End If
Exit Sub
delerr:
Rollback
MsgBox Err.Description
End SubPrivate Sub Command3_Click()
Dim position As Variant
Dim s As String
On Error GoTo updateerr
BeginTrans
Data1.Recordset.Update
CommitTrans
initial_button
Data1.Refresh
Exit Sub
updateerr:
Rollback
MsgBox Err.Description
End SubPrivate Sub Command4_Click()
On Error GoTo cancelerr
Data1.Recordset.CancelUpdate
initial_button
Exit Sub
cancelerr:
MsgBox Err.Description
End SubPrivate Sub Command5_Click()
Unload Me
End SubPrivate Sub Command6_Click()
Dim mynumber As String
mynumber = InputBox$("请输入学号(6位)", "学号搜索", "830001")
If mynumber = "学号='" & mynumber & "'" Then
Data1.Recordset.FindFirst mynumber
End If
End SubPrivate Sub Form_activate()
initial_button
End Sub添加时,操作怎么会提示被关联对象取消,无法保存啊
Data1.Recordset.AddNew
For i = 0 To 3
Data1.Recordset.fields(i) =text1(i).text
Text1(i).Text = ""
Next
Data1.Recordset.update
savecancel