为什么这会导致类型不匹配?

时间:2011-12-28 13:58:34

标签: sql vb6 crystal-reports

我有一个调用Crystal Report XI Report的VB6应用程序。但是,当我尝试更改连接信息时,我得到类型不匹配。任何帮助将不胜感激。

Dim Report As craxddrt.Report ' This is how Report is defined

ChangeReportTblLocation Report ' This is the function where the mismatch occurs

这是ChangeReportTblLocation

的定义
Private Function ChangeReportTblLocation(ByRef pReport As craxddrt.Report) As Boolean

    Dim ConnectionInfo  As craxddrt.ConnectionProperties
    Dim crxTables       As craxddrt.DatabaseTables
    Dim crxTable        As craxddrt.DatabaseTable
    Dim crxSections     As craxddrt.Sections
    Dim crxSection      As craxddrt.section
    Dim crxSubreportObj As craxddrt.SubreportObject
    Dim crxReportObjects As craxddrt.ReportObjects
    Dim crxSubreport    As craxddrt.Report
    Dim ReportObject    As Object
    Dim Y               As Integer
    Dim lsDatabase      As String

    On Error GoTo errHandle_CRTL


    lsDatabase = GetCurrentUserRoot("SOFTWARE\COTTSYSTEMS\APP", "Database")

    If lsDatabase = "" Then
        lsDatabase = gConn.DefaultDatabase
    End If

    If lsDatabase = "" Then
        lsDatabase = "frasys"
    End If

    With pReport

        For Y = 1 To .Database.Tables.Count
            Set ConnectionInfo = .Database.Tables(Y).ConnectionProperties

            ConnectionInfo.DeleteAll
            ConnectionInfo.Add "DSN", frasysdsn
            ConnectionInfo.Add "Database", lsDatabase

           'This is the Line that causes the type mismatch
            .Database.Tables(Y).Location = lsDatabase & ".dbo." & Database.Tables(Y).Location

        Next Y

        Set crxSections = .Sections

        For Each crxSection In crxSections

            Set crxReportObjects = crxSection.ReportObjects

            For Each ReportObject In crxReportObjects

                If ReportObject.Kind = crSubreportObject Then
                    Set crxSubreportObj = ReportObject
                    Set crxSubreport = crxSubreportObj.OpenSubreport
                    Set crxTables = crxSubreport.Database.Tables

                    For Y = 1 To crxTables.Count
                        Set crxTable = crxTables.Item(Y)
                        crxTable.Location = lsDatabase & ".dbo." & crxTable.Location

                    Next Y

                 End If
            Next ReportObject
        Next crxSection

    End With

    Set ConnectionInfo = Nothing
    Set crxTables = Nothing
    Set crxTable = Nothing
    Set crxSections = Nothing
    Set crxSection = Nothing
    Set crxSubreportObj = Nothing
    Set crxReportObjects = Nothing
    Set crxSubreport = Nothing
    Set ReportObject = Nothing

    ChangeReportTblLocation = True

    Exit Function
errHandle_CRTL:
    Screen.MousePointer = vbDefault
    MsgBox err.Number, err.Description, "ChangeReportTblLocation", err.Source
End Function

2 个答案:

答案 0 :(得分:3)

我认为这只是一个错字:

.Database.Tables(Y).Location = lsDatabase & ".dbo." & .Database.Tables(Y).Location

我在此行的第二个.之前添加了Database.Tables(Y).Location

这确实表明你没有在代码中使用Option Explicit。我不能强调使用它的重要性。这将节省你很多时间寻找奇怪的拼写错误(像这样)并保存你的代码,使其不会做各种奇怪的事情。

答案 1 :(得分:0)

尝试使用    call ChangeReportTblLocation(Report)