【问题标题】:ms access vba code for update records through formms通过表单访问vba代码更新记录
【发布时间】:2017-03-20 15:04:51
【问题描述】:

我是 MS Access 2007 的新手,我对 vba 几乎一无所知。 ...我有一个表名 F,其中包含字段 F1、F2、F3、F4、F5,其中前三个是数字字段,最后两个是文本字段。在带有文本框的表单中:txtF1、txtF2、txtF3、txtF4、txtF5 和命令按钮 cmdUpdate,我想更新表 F 中的 F5,其中 F1=txtF1、F2=txtF2、F3=txtF3 和 F4=txtF4 条件成立。 .. 请帮助提供完整的代码。

【问题讨论】:

  • 请阅读游览和How to Ask
  • 请帮忙提供完整的代码?你会拿着一张白纸走进教室,请老师给你答案吗?尝试解决问题,如果您的代码有特定问题,请返回此处。

标签: vba ms-access ms-access-2007


【解决方案1】:

在cmdUpdate按钮的点击事件中,需要放置一个生成sql命令的过程,然后执行。

Private Sub cmdUpdate_Click()

'Create a string variable to hold your sql command string
Dim strSQL As String

'Fill the variable with your sql command, plucking values out of your 
'form as shown using the Me. operator.  When using text values in your 
'string, wrap them with the Chr(34)'s, which will insert quotation marks in 
'your sql string when it's resolved.
strSQL = "UPDATE F SET F.F5 = " & Chr(34) & yourtextvaluehere & Chr(34) & _
            " WHERE F1=" & Me.txtF1 & _
            " AND F2=" & Me.txtF2 & _
            " AND F3=" & Me.txtF3 & _
            " AND F4=" & Chr(34) & Me.txtF4 & Chr(34)

'Execute the sql statement you've built against the database
CurrentDb.Execute strSQL, dbSeeChanges + dbFailOnError

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2018-05-16
    相关资源
    最近更新 更多