我有一个MS access 2010
数据库,该数据库连接到MS Excel 2010
以进行报告。我已使用excel中的Get External Data
选项将Excel链接到Access。由于报告要求变化不大,我必须在Access中创建new query
(并且它有一些custom function
)。 Custom Function is a VBA module in Access
。
不幸的是,当我在Excel中使用Get External Data
链接我的新访问查询时,新查询(View)未列在表/视图(导入向导)列表中。当我删除Custom Function
时,向导中会显示查询。
我的自定义函数连接行(取自其他网站)
Public Function ConcatADO(strSQL As String, strColDelim, _
strRowDelim, ParamArray NameList() As Variant)
Dim rs As New ADODB.Recordset
Dim strList As String
On Error GoTo Proc_Err
If strSQL <> "" Then
rs.Open strSQL, CurrentProject.Connection
strList = rs.GetString(, , strColDelim, strRowDelim)
strList = Mid(strList, 1, Len(strList) - Len(strRowDelim))
Else
strList = Join(NameList, strColDelim)
End If
ConcatADO = strList
Exit Function
Proc_Err:
ConcatADO = "***" & UCase(Err.Description)
End Function
以下是新查询中使用的JET SQL(在Access中可以正常工作)
SELECT DISTINCT
D.[Ref ID],
D.[ENTRYDATE],
D.[AUDITOR LID],
D.[Process],
D.[Auditee],
D.[Auditee Name],
D.[Account No],
D.[Auditee Manager],
D.[MaxScore],
D.[Score],
D.[Result],
ConcatADO("SELECT [COMMENTS] FROM ycube WHERE [Ref ID]=" & "'" & [d].[Ref ID] & "'" ,", "," : ") AS [Master Comment]
FROM ycube AS D;