如何通过IF语句中的sql命令更新表中的记录 [英] how to update a record in a table via a sql command within an IF statement

查看:244
本文介绍了如何通过IF语句中的sql命令更新表中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关闭一条记录,其中在表中有一个True/False列.在下面的代码中,我不断收到预期语句结尾的编译错误.我想念什么?在任何给定时间,只有一条记录为True.

I'm trying to close out a record, where I have a True/False column inside a table. Code below, I keep getting a compile error expected end of statement. What am I missing? It will only be one record that is True at any given time.

If Me.butCompleteFlight.Value = True Then 
    UPDATE tblFlightRecords SET strWorkingRecord = FALSE WHERE strWorkingRecord = TRUE

推荐答案

您不能这样混合SQL代码和VBA代码.
您可以使用方法 DoCmd.RunSQL执行更新语句:

You can't mix SQL code and VBA code like that.
You can execute the update statement with the method DoCmd.RunSQL:

If Me.butCompleteFlight.Value = True Then 
    Dim SQL As String 
    SQL = "UPDATE tblFlightRecords SET strWorkingRecord = FALSE WHERE strWorkingRecord = TRUE"
    DoCmd.RunSQL SQL
End If

这篇关于如何通过IF语句中的sql命令更新表中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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