VBA 类型不匹配错误

发布于 2025-01-02 12:08:21 字数 3237 浏览 1 评论 0原文

我不知道这是什么。显然它一定是某种语法错误,但我无法弄清楚它对我来说是什么!我所做的就是将数据保存到 SQL Server 2008 中的表中,并且我在 microsoft Dynamics Great Plains 2010 中使用 vba。它抛出错误的特定行是,

 rs("FREIGHT_RATE") = frmItemProfile.txtFreightRate

但每当我进行调整时它似乎都会更改行,所以有这个方法可能在某个地方出了问题。错误消息只说“类型不匹配”任何帮助都会很棒。

Public Sub SaveRecord(strItemNumber As String)
Dim qry As String
Set rs = New ADODB.Recordset

'query table name
    qry = "SELECT * FROM dbo.PCI_ITEM_PROFILE where ITEMNMBR = '" & strItemNumber & "'"

'open recordset
    rs.Open qry, strDSNPCI, adOpenStatic, adLockPessimistic

        If rs.EOF <> True Then
            'Time to Update Record
                rs("RCD_KEY") = frmItemProfile.txtRCDKey
                If frmItemProfile.txtCopyRightDate = "" Then
                    rs("COPYRIGHT_DATE") = #1/1/1900#
                Else
                    rs("COPYRIGHT_DATE") = frmItemProfile.txtCopyRightDate
                End If
                rs("FIRST_CATALOG") = frmItemProfile.txtFirstCatalog
                rs("CATEGORY") = frmItemProfile.txtCategory
                rs("SERIES_CD") = frmItemProfile.txtSeriesCD
                rs("PARENT_CD") = frmItemProfile.txtParentCD
                rs("TYPE") = frmItemProfile.txtType
                rs("COMMODITY_CD") = frmItemProfile.txtCommodityCD
                rs("BARCODE_1") = frmItemProfile.txtBarCodeOne
                rs("BARCODE_2") = frmItemProfile.txtBarCodeTwo
                rs("BARCODE_3") = frmItemProfile.txtBarCodeThree
                rs("BARCODE_4") = frmItemProfile.txtBarCodeFour
                rs("CLASS_GROUP") = frmItemProfile.cmbClassGroup
                rs("FREIGHT_RATE") = frmItemProfile.txtFreightRate
                rs("ITEM_LENGTH") = frmItemProfile.txtItemLength
                rs("ITEM_WIDTH") = frmItemProfile.txtItemWidth
                rs("ITEM_HEIGHT") = frmItemProfile.txtItemHeight
                rs("USER2ENT") = frmItemProfile.txtUserEnt
                rs("CREATE_DATE") = frmItemProfile.txtCreateDate
                rs("MODIFDT") = frmItemProfile.txtModifyDate
                rs("IN_KIT") = frmItemProfile.txtInKit
                rs("IN_BOM") = frmItemProfile.txtInBom
                rs("REP_COMM_PCT") = frmItemProfile.txtRepPct
                rs("REP_COMM_EXCEPT") = frmItemProfile.txtRepCommExcept
                rs("ROYALTY_ITEM") = frmItemProfile.txtRoyaltyItem
                rs("PPC_PAGES") = frmItemProfile.txtPPCPages
                rs("PPC_PAPER") = frmItemProfile.txtPPCPaper
                rs("PPC_TONERCURVE") = frmItemProfile.txtPPCTonerCurve
                rs("PPC_COIL") = frmItemProfile.txtPPCCoil
                rs("PPC_IMPRESSIONS") = frmItemProfile.txtPPCImpressions
                rs("DROP_SHIP_ITEM") = frmItemProfile.txtDropShipItem
                rs("OP_CD") = frmItemProfile.txtOPCD
                If frmItemProfile.txtOPDate = "" Then
                    rs("OP_DATE") = #1/1/1900#
                Else
                    rs("OP_DATE") = frmItemProfile.txtOPDate
                End If
                rs("NOTES") = frmItemProfile.txtNotes
                rs.Update
        End If
    rs.Close
    Set rs = Nothing
 End Sub

I have no clue what this is. Apparently it has to be some syntax error of some sort but I can not figure out what it is for the life of me! All I am doing is save data into a table in SQL Server 2008 and I am using vba in microsoft dynamics great plains 2010. The specific line it is throwing an error is

 rs("FREIGHT_RATE") = frmItemProfile.txtFreightRate

but it seems to change lines whenever I make an adjustment, so there is probably something wrong in this method somewhere. The error message only says "type mismatch" Any Help would be amazing.

Public Sub SaveRecord(strItemNumber As String)
Dim qry As String
Set rs = New ADODB.Recordset

'query table name
    qry = "SELECT * FROM dbo.PCI_ITEM_PROFILE where ITEMNMBR = '" & strItemNumber & "'"

'open recordset
    rs.Open qry, strDSNPCI, adOpenStatic, adLockPessimistic

        If rs.EOF <> True Then
            'Time to Update Record
                rs("RCD_KEY") = frmItemProfile.txtRCDKey
                If frmItemProfile.txtCopyRightDate = "" Then
                    rs("COPYRIGHT_DATE") = #1/1/1900#
                Else
                    rs("COPYRIGHT_DATE") = frmItemProfile.txtCopyRightDate
                End If
                rs("FIRST_CATALOG") = frmItemProfile.txtFirstCatalog
                rs("CATEGORY") = frmItemProfile.txtCategory
                rs("SERIES_CD") = frmItemProfile.txtSeriesCD
                rs("PARENT_CD") = frmItemProfile.txtParentCD
                rs("TYPE") = frmItemProfile.txtType
                rs("COMMODITY_CD") = frmItemProfile.txtCommodityCD
                rs("BARCODE_1") = frmItemProfile.txtBarCodeOne
                rs("BARCODE_2") = frmItemProfile.txtBarCodeTwo
                rs("BARCODE_3") = frmItemProfile.txtBarCodeThree
                rs("BARCODE_4") = frmItemProfile.txtBarCodeFour
                rs("CLASS_GROUP") = frmItemProfile.cmbClassGroup
                rs("FREIGHT_RATE") = frmItemProfile.txtFreightRate
                rs("ITEM_LENGTH") = frmItemProfile.txtItemLength
                rs("ITEM_WIDTH") = frmItemProfile.txtItemWidth
                rs("ITEM_HEIGHT") = frmItemProfile.txtItemHeight
                rs("USER2ENT") = frmItemProfile.txtUserEnt
                rs("CREATE_DATE") = frmItemProfile.txtCreateDate
                rs("MODIFDT") = frmItemProfile.txtModifyDate
                rs("IN_KIT") = frmItemProfile.txtInKit
                rs("IN_BOM") = frmItemProfile.txtInBom
                rs("REP_COMM_PCT") = frmItemProfile.txtRepPct
                rs("REP_COMM_EXCEPT") = frmItemProfile.txtRepCommExcept
                rs("ROYALTY_ITEM") = frmItemProfile.txtRoyaltyItem
                rs("PPC_PAGES") = frmItemProfile.txtPPCPages
                rs("PPC_PAPER") = frmItemProfile.txtPPCPaper
                rs("PPC_TONERCURVE") = frmItemProfile.txtPPCTonerCurve
                rs("PPC_COIL") = frmItemProfile.txtPPCCoil
                rs("PPC_IMPRESSIONS") = frmItemProfile.txtPPCImpressions
                rs("DROP_SHIP_ITEM") = frmItemProfile.txtDropShipItem
                rs("OP_CD") = frmItemProfile.txtOPCD
                If frmItemProfile.txtOPDate = "" Then
                    rs("OP_DATE") = #1/1/1900#
                Else
                    rs("OP_DATE") = frmItemProfile.txtOPDate
                End If
                rs("NOTES") = frmItemProfile.txtNotes
                rs.Update
        End If
    rs.Close
    Set rs = Nothing
 End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱,才寂寞 2025-01-09 12:08:21

这是一个可能的重现:

Dim rs
Set rs = CreateObject("ADODB.Recordset")

With rs
  .Fields.Append "FREIGHT_RATE", adDouble, , 32  ' adFldIsNullable
  .Open
  .AddNew
  rs("FREIGHT_RATE") = "fifty-five"

End With

我得到的错误:

多步操作产生错误。检查每个状态值。

Here's a possible repro:

Dim rs
Set rs = CreateObject("ADODB.Recordset")

With rs
  .Fields.Append "FREIGHT_RATE", adDouble, , 32  ' adFldIsNullable
  .Open
  .AddNew
  rs("FREIGHT_RATE") = "fifty-five"

End With

The error I get:

Multiple-step operation generated errors. Check each status value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文