|
本人是新手在用INSERT INTO 向数据表保存数据时,提示语法错误,请各位老师指教!
谢谢!
Private Sub 保存档案_Click()
On Error GoTo Err_保存档案_Click
Dim i As Integer
Dim STemp As String
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
'为打开数据表"查询语句"字符变量赋值
STemp = "Select * From 患者信息"
'打开"患者信息"数据表
Rs.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockBatchOptimistic
'判断"患者ID"等文本框是否为空
If IsNull(Me![患者ID]) = True Then
'弹出提示"患者ID"文本框不可以为空信息
MsgBox "请输入患者ID,它不可以为空!", vbOKOnly, "输入 患者ID"
'把光标置于"患者ID"文本框内
Me![患者ID].SetFocus
'退出子过程
Exit Sub
ElseIf IsNull(Me![姓名]) = True Then
MsgBox "请输入姓名, 它不可为空!", vbOKOnly, "输入 姓名"
Me![姓名].SetFocus
'退出子过程
Exit Sub
ElseIf IsNull(Me![性别]) = True Then
MsgBox "请输入性别, 它不可为空!", vbOKOnly, "输入 性别"
Me![性别].SetFocus
'退出子过程
Exit Sub
ElseIf IsNull(Me![年龄]) = True Then
MsgBox "请输入年龄, 它不可为空!", vbOKOnly, "输入 年龄"
Me![年龄].SetFocus
'退出子过程
Exit Sub
ElseIf IsNull(Me![登记日期]) = True Then
MsgBox "请输入登记日期, 它不可为空!", vbOKOnly, "输入 登记日期"
Me![登记日期].SetFocus
'退出子过程
Exit Sub
Else
'循环判断该编号的档案是否存在
If Rs.RecordCount > 0 Then
Rs.MoveFirst
For i = 1 To Rs.RecordCount
'如果存在,弹出信息并退出子过程
If Rs("患者ID") = Me![患者ID] Then
MsgBox "该编号的档案已经存在,请核实!", vbCritical, "记录已经存在"
Exit Sub
Else
Rs.MoveNext
End If
Next i
End If
End If
'为保存医生档案"查询语句"字符变量赋值
STemp = "INSERT INTO 患者信息"
STemp = STemp & "( [患者ID],姓名,性别,年龄,籍贯,民族,"
STemp = STemp & "出生日期,登记日期,婚姻,身份证号,联系电话,家庭住址,"
STemp = STemp & "所在单位,E-mail,备注,主诉,现病史,既往史,"
STemp = STemp & "查体,处置意见,术前诊断,手术名称,手术日期,麻醉方式,"
STemp = STemp & "重要情况和特殊问题,手术方案,手术告知内容,术后诊断,手术医师,麻醉医师,"
STemp = STemp & "手术次数,器械护士,手术经过)"
STemp = STemp & "VALUES ('" & Me![患者ID] & "','" & Me![姓名] & "',"
STemp = STemp & "'" & Me![性别] & "','" & Me![年龄] & "',"
STemp = STemp & "'" & Me![籍贯] & "','" & Me![民族] & "',"
STemp = STemp & "'" & Me![出生日期] & "',"
STemp = STemp & "'" & Me![登记日期] & "','" & Me![婚姻] & "',"
STemp = STemp & "'" & Me![身份证号] & "','" & Me![联系电话] & "',"
STemp = STemp & "'" & Me![E-mail] & "','" & Me![备注] & "',"
STemp = STemp & "'" & Me![家庭住址] & "','" & Me![所在单位] & "',"
STemp = STemp & "'" & Me![主诉] & "','" & Me![现病史] & "',"
STemp = STemp & "'" & Me![既往史] & "','" & Me![查体] & "',"
STemp = STemp & "'" & Me![处置意见] & "','" & Me![术前诊断] & "',"
STemp = STemp & "'" & Me![手术名称] & "','" & Me![手术日期] & "',"
STemp = STemp & "'" & Me![麻醉方式] & "','" & Me![重要情况和特殊问题] & "',"
STemp = STemp & "'" & Me![手术方案] & "','" & Me![手术告知内容] & "',"
STemp = STemp & "'" & Me![术后诊断] & "','" & Me![手术医师] & "',"
STemp = STemp & "'" & Me![麻醉医师] & "','" & Me![手术次数] & "',"
STemp = STemp & "'" & Me![器械护士] & "','" & Me![手术经过] & "')"
'使用DoCmd对象的RunSQL方法执行查询
DoCmd.RunSQL STemp
'刷新“患者信息查询 子窗体”子窗体
Me![患者信息查询 子窗体].Requery
'释放系统为Rs数据集分配的 |
|