Office中国论坛/Access中国论坛

标题: 请帮忙看看这段代码哪里出错了 [打印本页]

作者: 海角天涯    时间: 2010-3-18 13:44
标题: 请帮忙看看这段代码哪里出错了
大家好
我是access新手
现想请大家帮我看看下面这段代码哪里出错了
谢谢
  1. Private Sub 保存信息_Click()
  2. On Error GoTo Err_保存信息_Click:
  3. Dim Stemp As String
  4. If Me![职员ID] <> "" Then
  5. Stemp = "insert into 职员内部调动"
  6. Stemp = Stemp & "(职员ID,姓名,性别,原部门,新部门,调动日期,调动原因,备注)"
  7. Stemp = Stemp & "values('" & Me![职员ID] & "','" & Me![姓名] & "',"
  8. Stemp = Stemp & "'" & Me![性别] & "'," & Me![原部门] & "',"
  9. Stemp = Stemp & "'" & Me![新部门] & "'," & Me![调动日期] & "',"
  10. Stemp = Stemp & "'" & Me![调动原因] & "'," & Me![备注] & "')"
  11. DoCmd.RunSQL Stemp
  12. Stemp = "update 职员基本资料"
  13. Stemp = Stemp & "set 部门ID='" & Me![新部门ID] & "'"
  14. Stemp = Stemp & "where 职员ID='" & Me![职员ID] & "'"
  15. DoCmd.RunSQL Stemp
  16. Else
  17. MsgBox "'职员ID'不能为空,请重新输入!", vbOKOnly, "警告"
  18. Me![职员ID].SetFocus
  19. End If
  20. Me![职员内部调动管理子窗体].Requery
  21. exit_保存信息_click:
  22. Exit Sub
  23. Err_保存信息_Click:
  24. MsgBox Err.Description
  25. Resume exit_保存信息_click
  26. End Sub
复制代码

[attach]41711[/attach]
作者: 咱家是猫    时间: 2010-3-18 13:50
Stemp = Stemp & "'" & Me![新部门] & "'," & Me![调动日期] & "',"
这一句,改成
Stemp = Stemp & "'" & Me![新部门] & "',#" & Me![调动日期] & "#,"
作者: leijiqiang    时间: 2010-3-18 14:03
Stemp = Stemp & "(职员ID,姓名,性别,原部门,新部门,调动日期,调动原因,备注)"

Stemp = Stemp & "values('" & Me![职员ID] & "','" & Me![姓名] & "',"

把第二句改为Stemp = Stemp & "  values('" & Me![职员ID] & "','" & Me![姓名] & "',"多加一个空格

Stemp = "update 职员基本资料"

Stemp = Stemp & "set 部门ID='" & Me![新部门ID] & "'"

Stemp = Stemp & "where 职员ID='" & Me![职员ID] & "'"

这三句都加空格隔开
Stemp = Stemp & "'" & Me![新部门] & "'," & Me![调动日期] & "',"
这一句,改成
Stemp = Stemp & "'" & Me![新部门] & "',#" & Me![调动日期] & "#,"
作者: 海角天涯    时间: 2010-3-18 14:05
Stemp = Stemp & "'" & Me![新部门] & "'," & Me![调动日期] & "',"
这一句,改成
Stemp = Stemp & "'" & Me![新部门] & "',#" & Me![调动日期] & "#,"
咱家是猫 发表于 2010-3-18 13:50


我按您的方法修改了,可是还是显示错误哦
[attach]41712[/attach]
作者: kangking    时间: 2010-3-18 14:13
薪资不变  前差个引号后又多一个引号。
作者: 咱家是猫    时间: 2010-3-18 14:24
Stemp = Stemp & "'" & Me![调动原因] & "'," & Me![备注] & "')"
改成
Stemp = Stemp & "'" & Me![调动原因] & "','" & Me![备注] & "')"
作者: 咱家是猫    时间: 2010-3-18 14:25
这些都是自己不够认真的原因.
作者: 海角天涯    时间: 2010-3-18 14:38
薪资不变  前差个引号后又多一个引号。
kangking 发表于 2010-3-18 14:13


加上引号,问题解决
谢谢

  1. Stemp = Stemp & "values('" & Me![职员ID] & "','" & Me![姓名] & "',"
  2. Stemp = Stemp & "'" & Me![性别] & "','" & Me![原部门] & "',"
  3. Stemp = Stemp & "'" & Me![新部门] & "','" & Me![调动日期] & "',"
  4. Stemp = Stemp & "'" & Me![调动原因] & "','" & Me![备注] & "')"
复制代码





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3