我正在尝试将不同的表名作为字符串传递,以便它们可以在将我指定的表导出到 Excel 电子表格的函数中使用。我无法让它工作,因为当我尝试执行“DoCmd.TransferSpreadsheet”命令时,它说它无法识别“table_name”。我认为如果我传递一个带有表名的字符串名称,它将起作用,但显然它没有。我是否传递了错误的字符串,或者我不允许这样做?另外,我应该将它导出为什么类型的 Excel 电子表格?我没有看到不同类型之间的差异。
Public Function NAME_FILE(table_name As String)
Dim strName As String
Dim strLocation As String
Dim strXLS As String
Dim strFinalName As String
strName = InputBox("What do you want to name the file?", "File Name")
strLocation = "C:\folder1\"
strXLS = ".xls"
strFinalName = strLocation & "" & strName & "" & strXLS
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "table_name", strFinalName, True
End Function
Public Function EXPORT_PRODUCT_CODE()
Dim T_PRODUCT_CODE As String
NAME_FILE (T_PRODUCT_CODE)
End Function
Public Function EXPORT_CAMPAIGN_CODE()
Dim T_CAMPAIGN_CODE As String
NAME_FILE (T_CAMPAIGN_CODE)
End Function