添加数据的代码写好了,可是修改记录的代码怎么写都显示错误。
下面是添加记录的代码。请教修改记录的代码。Private Sub cmdAdd_Click()
Dim sc As Integer
If Not (Testtxt(txtNo.Text) Or Testtxt(txtName.Text) Or Testtxt(txtSex.Text) Or Testtxt(txtBookTime.Text) Or Testtxt(txtTel.Text) Or Testtxt(txtEnrolTime.Text)) Then
MsgBox "带 * 号为必填项", vbOKOnly + vbExclamation, "警告"
txtNo.SetFocus
Exit Sub
End If
sc = MsgBox("确实要添加这条记录吗?", vbOKCancel, "提示信息")
If sc = 1 Then
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=C:\Users\sAnKes\Desktop\大学生心理健康中心\data.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3
strSQL = "select * from 预约者"
rs.Open strSQL, conn, 3, 3
rs.AddNew
rs!编号 = txtNo.Text
rs!姓名 = txtName.Text
rs!性别 = txtSex.Text
rs!所在学院 = txtCollege.Text
rs!所在专业 = txtSpeciality.Text
rs!联系电话 = txtTel.Text
rs!预约时间 = txtBookTime.Text
rs!登记时间 = txtEnrolTime.Text
rs!备注 = txtRemark.Text
rs.Update
rs.Close
conn.Close
MsgBox ("添加记录成功!")
Adodc1.Refresh
End If
txtNo.Text = ""
txtName.Text = ""
txtSex.Text = ""
txtCollege.Text = ""
txtSpeciality.Text = ""
txtTel.Text = ""
txtBookTime.Text = ""
txtEnrolTime.Text = ""
txtRemark.Text = ""
End Sub
Private Sub cmdEdit_Click()
Dim sc As Integer
Frame2.Visible = True
Frame1.Visible = False
cmdAdd.Enabled = False
cmdDelect.Enabled = False
cmdPrint.Enabled = False
cmdPutout.Enabled = False
cmdEdit.Caption = "保存"
txtNo.Text = Text2(0)
txtName.Text = Text2(1)
txtSex.Text = Text2(2)
txtCollege.Text = Text2(3)
txtSpeciality.Text = Text2(4)
txtTel.Text = Text2(5)
txtBookTime.Text = Text2(6)
txtEnrolTime.Text = Text2(7)
txtRemark.Text = Text2(8)
If Not (Testtxt(txtNo.Text) Or Testtxt(txtName.Text) Or Testtxt(txtSex.Text) Or Testtxt(txtBookTime.Text) Or Testtxt(txtTel.Text) Or Testtxt(txtEnrolTime.Text)) Then
MsgBox "带 * 号为必填项", vbOKOnly + vbExclamation, "警告"
txtNo.SetFocus
Exit Sub
End If
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=C:\Users\sAnKes\Desktop\大学生心理健康中心\data.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3
strSQL = "select * from 预约者"
rs.Open strSQL, conn, 1, 3
rs!编号 = 1
rs!姓名 = txtName.Text
rs!性别 = txtSex.Text
rs!所在学院 = txtCollege.Text
rs!所在专业 = txtSpeciality.Text
rs!联系电话 = txtTel.Text
rs!预约时间 = 2004 - 2 - 2
rs!登记时间 = 2004 - 2 - 2
rs!备注 = txtRemark.Text
rs.Update
rs.Close
conn.Close
Adodc1.Refresh
End Sub