ADD / UPDATE BUTTON语法错误 [英] ADD/UPDATE BUTTON syntax error

查看:171
本文介绍了ADD / UPDATE BUTTON语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im当前编码我的添加/更新按钮在MS Access 2013,但由于一些奇怪的原因,我有麻烦试图使它的工作所有它告诉我是我有一个'语法错误UPDATE语句...这里是我的代码总体:

Im currently coding my Add/Update button in MS Access 2013 but for some odd reason im having trouble trying to make it work all it tells me is that I have a 'syntax error on the UPDATE statement'... here is my code overall:

    Private Sub cmdAdd_Click()
    'In the button add we have two options
    '1. Insert
    '2. Update
    If Me.txtID.Tag & "" = "" Then

    CurrentDb.Execute "INSERT INTO tblClients ( ClientID, ClientName, Gender, " & _
                             "City, [Address (Fisical)], [Cellphone/Telephone] ) " & _
                                "SELECT " & Me.txtID & ",'" & Me.txtName & "','" & Me.cboGender & "', '" & Me.cboCity & "','" & Me.txtAddress & "','" & Me.txtCellphone & "'"
    Else
    'Otherwise the data will be updated
    CurrentDb.Execute "UPDATE tblClients" & _
    "SET ClientID =" & Me.txtID & _
    ", ClientName='" & Me.txtName & "'" & _
    ", Gender='" & Me.cboGender & "'" & _
    ", City='" & Me.cboCity & "'" & _
    ", Cellphone/Telephone='" & Me.txtCellphone & "'" & _
    ", Address (Fisical) ='" & Me.txtAddress & "'" & _
    "WHERE ClientID =" & Me.txtID.Tag


    End If


   cmdClear_Click

   tblClients_subform.Form.Requery


   End Sub

请帮助需要

推荐答案

看起来很接近,这样想,因为我知道它会让我失望。如果错误说语法错误,它不撒谎,更经常的不是对我来说,是不能看到树木的木头。您缺少几个空格: -

Looks close, think of it this way because i know it frustrates me when it happens. If the error says syntax error, its not lying, and more often than not for me it was not being able to see the wood for the trees. You're missing a few spaces:-

CurrentDb.Execute "UPDATE [tblClients]" & _
" SET [ClientID] =" & Me.txtID & _
", [ClientName]='" & Me.txtName & "'" & _
", [Gender]='" & Me.cboGender & "'" & _
", [City]='" & Me.cboCity & "'" & _
", [Cellphone/Telephone]='" & Me.txtCellphone & "'" & _
", [Address (Fisical)] ='" & Me.txtAddress & "'" & _
" WHERE [ClientID] =" & Me.txtID.Tag




  • 之前的空格ClientID ...


  • 包括列和表名

  • 还有一个诀窍: -

    Also a trick I learned for this: -


    1. 打开一个新查询并查看SQL

    2. 粘贴已执行的字符串

    3. 运行

    您会得到更多关于问题所在位置的信息。

    You get more info on where the issue is.

    这篇关于ADD / UPDATE BUTTON语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆