2011-12-28 8 views
0

Crystal Report XIレポートを呼び出すVB6アプリケーションがあります。しかし、接続情報を変更しようとすると、型の不一致が発生します。どんな助けもありがとう。これは型の不一致を引き起こすのはなぜですか?

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

私は.前を追加しました:

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 

答えて

3

を使用してみてください:

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

ChangeReportTblLocation Report ' This is the function where the mismatch occurs 

この

ChangeReportTblLocationの定義ですこのlの2番目の Database.Tables(Y).Location ine。

これはあなたのコードにOption Explicitを使用していないことを示唆しています。私はこれを使うことがいかに重要であるかを強く強調することはできません。奇妙なタイプミス(このような)を探して、あなたのコードをあらゆる種類の奇妙なことをするのから救うために、多くの時間を節約できます。

0

が、私はそのちょうど誤植が思う call ChangeReportTblLocation(Report)

+0

VB6でサブスクリプトを呼び出す必要はありません。また、戻り値を使用しない場合は関数を呼び出す必要はありません。 –

関連する問題