在ADODB Recordset循环期间,在vb6中键入不匹配错误13

时间:2017-01-05 17:54:25

标签: ms-access vb6 adodb

Private Sub cmdShow_Click()
    'lblTotPur/lblTotPayRet/lblBalance
    Dim strShow, mSlNo
    Dim rsShow As New ADODB.Recordset
    Dim NewItem As Variant
    If Trim(txtCustomer.Text) = "" Then
        MsgBox "Please select vendor to proceed...", vbCritical, POPUP_COMP
        Exit Sub
    End If

    Dim recCnt
    pgrPartyLedger.Min = 0
    recCnt = 0
    'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser CASH PURCHASE RETURN
    strShow = "select Count(*) as mCnt from VOUCHMST A,VOUCHDAT B, mPurchase C "
    strShow = strShow & " where A.VNO=B.VNO and (A.REMARKS='CASH PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE' OR A.REMARKS='CASH PURCHASE' OR A.REMARKS='PAYMENT' OR A.REMARKS='CREDIT NOTE') "
    strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
    strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
    strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
    strShow = strShow & " and A.VREFNO = C.PurBillNo  "
    'strShow = strShow & " order by A.ID,A.DATED,A.VNO"
    rsShow.Open strShow, cn
    recCnt = rsShow("mCnt")
    rsShow.Close
    pgrPartyLedger.Max = recCnt + 1

    'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser
    strShow = "select A.Id,A.cmnt,A.VNO,A.DATED,B.IDNO,B.IDNAME,B.AMOUNT,B.DR_CR,B.VNARRATION,A.REMARKS,C.DealInvNo, B.CQ_TYPE, B.BANKNAME, B.BANKBRANCH, B.CQ_NO from VOUCHMST A,VOUCHDAT B,mPurchase C "
    strShow = strShow & " where A.VNO=B.VNO and (A.REMARKS='CASH PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE' OR A.REMARKS='CASH PURCHASE' OR A.REMARKS='PAYMENT' OR A.REMARKS='CREDIT NOTE') "
    strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
    strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
    strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
     strShow = strShow & " and A.VREFNO = C.PurBillNo  "
    strShow = strShow & " order by A.ID,A.DATED,A.VNO"
    rsShow.Open strShow, cn

    Dim mPur, mPayRet, mAnyAdv, mTempVNO
    mPur = 0
    mPayRet = 0
    mAnyAdv = 0

    mSlNo = 1
    ShowPaymentHeader
    Do While Not rsShow.EOF
        mTempVNO = rsShow("VNO")

        Set NewItem = listViewPayment.ListItems.Add(, "C" & mSlNo, Format(rsShow("DATED"), "dd/MM/yyyy"))
        NewItem.SubItems(1) = rsShow("VNO")
        NewItem.SubItems(13) = rsShow("DealInvNo")

        NewItem.SubItems(2) = IIf(IsNull(rsShow("IDNAME")), "", CommaFilterText(rsShow("IDNAME"), 1))
        If Trim(rsShow("REMARKS")) = "CASH PURCHASE" Then
            NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT"))
            NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
        ElseIf Trim(rsShow("REMARKS")) = "CREDIT PURCHASE" Then
            mAnyAdv = ShowPartialAdvance(rsShow("VNO"))
            NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT") + Val(mAnyAdv))
            If Val(mAnyAdv) > 0 Then
                NewItem.SubItems(4) = FormatTakaPaisa(mAnyAdv)
            Else
                NewItem.SubItems(4) = ""
            End If
        Else
            NewItem.SubItems(3) = ""
            NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
            NewItem.SubItems(7) = rsShow("CQ_TYPE")
            NewItem.SubItems(8) = rsShow("BANKNAME")
            NewItem.SubItems(9) = rsShow("BANKBRANCH")

            **    
            > NewItem.SubItems(9) = rsShow("cmnt")

            **

        End If
        NewItem.SubItems(6) = rsShow("IDNO")

        mPur = mPur + Val(NewItem.SubItems(3))
        mPayRet = mPayRet + Val(NewItem.SubItems(4))

        NewItem.SubItems(5) = rsShow("REMARKS")
        NewItem.SubItems(12) = GetVoucherRefNo(mTempVNO)

        pgrPartyLedger.Value = mSlNo

        mSlNo = mSlNo + 1
        rsShow.MoveNext
    Loop
    rsShow.Close

    lblTotPur.Caption = FormatTakaPaisa(mPur)
    lblTotPayRet.Caption = FormatTakaPaisa(mPayRet)
    lblBalance.Caption = FormatTakaPaisa(mPur - mPayRet)
    pgrPartyLedger.Value = 0        
End Sub

我收到该行的类型不匹配运行时错误13,请帮帮我

1 个答案:

答案 0 :(得分:0)

根据您的数据库设计和查询,您可能包含具有空值的字段或具有零长度字符串的字段。 您应该始终检查这一点,尤其是当您执行外部联接或查询中的多个联接时。

如果只检查一个表的内容并且看到所有字段都已填充,则这并不意味着结果集将仅返回有效值 - 但这超出了此答案的范围。 / p>

在处理Recordset时,有多种常见做法可以检查Field值和陷阱错误。仅举几例:

  1. On Error Resume ...阻止:避免这种情况,你还没有概述 发生了什么
  2. 检查Null值,DBNull值,Empty值或检查Field Type。只有一个 例如:

    If IsNull(rsShow("cmnt").value) = True Then NewItem.SubItems(9) = "" Else NewItem.SubItems(9) = rsShow("cmnt") End If

    注意:您应该明确字段的value属性。

    如果您进行字段类型检查,请学习使用VB IDE中集成的对象浏览器,这将是您最好的朋友。

  3. 检查字段的ActualSize属性:请参阅MSDN:The Field Object

  4. 另一个常见的快捷方式是在字段的返回值前加上或附加零长度的字符串,这仅在您不必区分Null值和Blank值,您只需要在标签或列表中显示结果,如下所示: NewItem.SubItems(9) = "" & rsShow("cmnt")

  5. 关于Error 13:在VB IDE中,打开Immediate Window,输入:? 0 = "",然后按Enter键。结果是什么?

    最后但并非最不重要的是,总是仔细检查字段的名称,每个数据库开发人员都会因拼写错误而面临错误,特别是在处理具有数十个表和数百个字段的财务应用程序时。