设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1280|回复: 1
打印 上一主题 下一主题

[与其它组件] 求教:INSERT INTO 语法错误

[复制链接]
跳转到指定楼层
1#
发表于 2006-10-22 21:36:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本人是新手在用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数据集分配的
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2006-10-23 01:08:00 | 只看该作者
搞定!! E-mail加[ ][em14]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-15 09:30 , Processed in 0.132022 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表