当前位置:编程学习 > VB >>

这段VB代码有问题吗?运行时提示类型不匹配

整个程序是这样,在EXCEL里输入输出数据,在ACCESS里存储数据,点这个按键时把相应查询到的数据显出在ECXEL的chart
Private Sub CommandButton3_Click()

    Dim path As String
     'path = "C:\Mass Banlance\"
     path = ActiveWorkbook.path & "\"

    With ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
        .Connection = Array(Array( _
        "ODBC;DSN=MS Access Database;DBQ=" + path + "Master_data.mdb;DefaultDir=" + path + ";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTime" _
        ), Array("out=5;"))
        .CommandType = xlCmdSql
        .CommandText = Array( _
        "SELECT Corporation_Index.Corporation, Month_Index.Month_name, Product_Index.Product, Production_Table.Year, Production_Table.Value, Unit_Index.Unit" & Chr(13) & "" & Chr(10) & "FROM `" + path + "Master_data`.Corporation_Index Corp" _
        , _
        "oration_Index, `" + path + "Master_data`.Month_Index Month_Index, `" + path + "Master_data`.Product_Index Product_Index, `" + path + "Master_data`.Production_Table Production_Table, `" + path + "Master_data`." _
        , _
        "Unit_Index Unit_Index" & Chr(13) & "" & Chr(10) & "WHERE Corporation_Index.Corporation_ID = Production_Table.Corporation_ID AND Month_Index.Month = Production_Table.Month AND Product_Index.Product_ID = Production_Table.Product_I" _
        , _
        "D AND Production_Table.Unit_ID = Unit_Index.Unit_ID AND ((Product_Index.Product='Crude Oil') AND (Unit_Index.Unit='thousand tonnes'))" _
        )
        .CreatePivotTable TableDestination:="", TableName:= _
        "Crude Oil Production (thousand tonnes)", DefaultVersion:=xlPivotTableVersion10
    End With
'    ActiveChart.PlotArea.Select
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    With ActiveSheet.PivotTables("Crude Oil Production (thousand tonnes)")
        .ColumnGrand = False
        .HasAutoFormat = False
        .RowGrand = False
    End With
    ActiveSheet.PivotTables("Crude Oil Production (thousand tonnes)").AddFields RowFields:= _
        "Month_name", ColumnFields:="Corporation", PageFields:="Year"
    ActiveSheet.PivotTables("Crude Oil Production (thousand tonnes)").PivotFields("Value"). _
        Orientation = xlDataField
    Charts.Add
    ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:="B&W Column"
    ActiveChart.Location Where:=xlLocationAsNewSheet
    ActiveChart.PivotLayout.PivotTable.PivotFields("Year").CurrentPage = "2006"
'    With ActiveChart.PivotLayout.PivotTable.PivotFields("Corporation")
'        .PivotItems("Total").Visible = False
'    End With
    
'add title
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Crude Oil Production (thousand tonnes)"
    End With
    ActiveChart.ChartTitle.Select
    Selection.AutoScaleFont = True
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Bold"
        .Size = 16
    End With
    
    ActiveChart.DataTable.Select
    Selection.Delete
    ActiveChart.HasLegend = True
    
    ActiveWorkbook.ShowPivotTableFieldList = False
    Application.CommandBars("PivotTable").Visible = False
    


End Sub
--------------------编程问答-------------------- 好长又好乱,一看就头晕
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,