VBA类型不匹配错误

时间:2012-02-02 19:08:28

标签: sql sql-server-2008 vba dynamics-gp

我不知道这是什么。显然它必须是某种语法错误,但我无法弄清楚它对我的生活是什么!我所做的只是将数据保存到SQL Server 2008中的表中,我在微软动态大平原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

1 个答案:

答案 0 :(得分:0)

这是一个可能的复制品:

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

我得到的错误:

  

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