【问题标题】:MySQL filter two field in recordset error on Update - VBA Excel - Run-time error '-2147467259 (80004005)'MySQL 在更新时过滤记录集中的两个字段错误 - VBA Excel - 运行时错误'-2147467259 (80004005)'
【发布时间】:2021-03-15 21:09:37
【问题描述】:

我有一个 MySQL 数据库,我从中请求一个客户记录集,然后我根据两个字段过滤特定客户的记录集:1) 客户代码和 2) 适用年份。然后,我将用户表单对象中的值分配给 MySQL 字段,并将该特定客户端的记录更新到数据库中。

更新表时出现以下错误(运行“rstIT.Update”),我认为这与我实现过滤器的方式有关:

运行时错误“-2147467259 (80004005)”:[MySQL][ODBC 8.0(w) 驱动程序][mysqld-5.5.5-10.2.36-MariaDB-log-cll-lve]构建位置-> insert_fields() 失败

我确信必须有一种更简单/更聪明的方法来过滤正确的客户,并相应地更新记录。任何帮助解决我当前的问题或其他方法将不胜感激!

Dim cn As ADODB.Connection
Dim rstIT As ADODB.recordSet
Dim rstClients As ADODB.recordSet

Dim Jaar As String

Jaar = cboTaxPeriod.Text
ITID = lblClientCode.Caption

Application.DisplayAlerts = False

Dim str As String

str = "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=myserveraddress;DATABASE=mydatabasename;PORT=myport;UID=user_"
str = str & LCase(LoggedInName)
str = str & ";PWD="
str = str & Password
str = str & ";FOUND_ROWS=1;"

Set cn = New ADODB.Connection
cn.ConnectionString = str
cn.Open
Set rstIT = New ADODB.recordSet

With rstIT
    .Open "IT", cn, adOpenKeyset, adLockOptimistic, adCmdTable
End With

    rstIT.Filter = "ClientCode = '" & ITID & "' AND TaxYear = '" & Jaar & "'"

        If rstIT.EOF Then
            MsgBox "Client code does not exist in tax table.", vbOKOnly, "Choose new client code"
            GoTo GaanUit 'This closes everything and exits
        Else
            rstIT!TaxStatus.value = LTrim(RTrim(cboTaxStatus.Text))
            rstIT!TaxStatusStaff.value = RTrim(LTrim(lblTaxStatusStaff.Caption))
            
            If lblDueDate.Caption <> "" Then
                lblDueDate.Caption = Format(lblDueDate.Caption, "yyyy-mm-dd")
                rstIT!DueDate.value = lblDueDate.Caption
            Else
                rstIT!DueDate = Empty
            End If
                        
        End If

rstIT.Update

【问题讨论】:

  • 你有一个 mariadb 并使用 mysql 8 驱动程序,你是否尝试了 mariadb 驱动程序?
  • nbk - 我将看看 MariaDB 驱动程序。据我所知,数据库是 MySQL。我对 MariaDB 不熟悉。
  • 您的错误消息显示 5.5.5-10.2.36-MariaD 这仍然很旧,因为我们现在有 10.4 及更高版本

标签: mysql vba filter


【解决方案1】:

我的猜测是,codeyear 是数字,因此没有引号:

rstIT.Filter = "ClientCode = " & ITID & " AND TaxYear = " & Jaar & ""

【讨论】:

  • 目前这两个字段都是字符串。年份实际上应该是数字,但字符串用于测试目的。不应该影响过滤器在更新记录时的工作方式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-03-24
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 2022-07-08
  • 1970-01-01
  • 2022-11-22
相关资源
最近更新 更多