Excel不会从Access导入表

时间:2011-07-28 15:14:57

标签: excel ms-access

我正在使用Excel / Access 2007.我在Access中创建了Access查询,并尝试使用“数据”选项卡将其导入Excel - >获取外部数据子选项卡 - >来自Access。我选择了我的数据库,并选择了我想导入的查询。但是,只显示表格的标题以及2个空白行(正如它们被格式化为表格所证明)。肯定会在查询中返回数据,我可以通过检查Access来验证。任何帮助将不胜感激

顺便说一句,这可以以编程方式完成吗?

编辑:这是所有荣耀中的SQL查询

SELECT [Meter#], [LDC#], [ESCO#], [Brand], [LDCName], [RateClass], [RateSubClass], [CustName],   
[DemandZone], [Type], dbo_Forecasts.Name AS ForecasForecastType, 
Min(IntervalMeterConsumption.[DateFrom]) AS ConsumptionStart, IntermediateLog.[MaxOfDateRead] AS ConsumptionEnd, 
Sum([kWh])/(Sum([Interval])/365) AS AverageAnnual

FROM (IntermediateLog 
        INNER JOIN (
                    (Premise INNER JOIN Meters ON Premise.PremiseCt = Meters.PremiseCt) 
                    INNER JOIN IntervalMeterConsumption 
                        ON Meters.Meterid = IntervalMeterConsumption.MeterID) 
            ON IntermediateLog.[LDC#] = Premise.CustomerPremiseNo) 
INNER JOIN dbo_Forecasts ON Meters.ForecastID = dbo_Forecasts.ForecastID

WHERE ((([MaxOfDateRead]-[DateFrom])<=380))

GROUP BY IntermediateLog.[Meter#], IntermediateLog.[LDC#], IntermediateLog.[ESCO#], 
IntermediateLog.Brand, IntermediateLog.LDCName, IntermediateLog.RateClass, 
IntermediateLog.RateSubClass, IntermediateLog.CustName, IntermediateLog.DemandZone, 
IntermediateLog.Type, dbo_Forecasts.Name, IntermediateLog.MaxOfDateRead;

1 个答案:

答案 0 :(得分:0)

您可以尝试暂时删除where子句,看看是否会产生影响。

在Access中运行查询时,它是否要求参数?

从Access导出查询到Excel的代码如下:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "Query/Table Name", "c:\export.xls"

感谢Mark