我使用Recordset将Access表单中的5个查询导出到Excel,方法是循环Excel对象并在每次循环时创建新的Excel。最后,当我想突出显示第一张表时,它会抛出错误号:1004
<code>
'Once the loop ends
xlWorkbook.Sheets("xlsheet1").Select
xlSheet.Range("A3").Select
</Code>
But when I select the last sheet which is by default highlighted I don't get the error.
<code>
'Once the loop ends
xlWorkbook.Sheets("xlsheet5").Select
xlSheet.Range("A3").Select
</Code>
Can someone help me with this.
Thanks in Advance.
答案 0 :(得分:0)
就像这一样简单。
Private Sub Command0_Click()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel10, "Query1", _
"C:\Users\your_path\access_export.xlsx", True, "Query1"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel10, "Query2", _
"C:\Users\your_path\access_export.xlsx", True, "Query2"
End Sub
以下是'DoCmd.TransferSpreadsheet acExport'功能参数的屏幕截图:
所以,倒数第二个参数是工作表名称。有关详细信息,请参阅此内容。
http://access-excel.tips/access-vba-cocmd-transferspreadsheet/
最后,这样的事情对你有用。
选项比较数据库
SELECT f1.userid,
f1.friendid,
y.username AS UserName,
x.username AS FriendName
FROM friends f1
INNER JOIN (SELECT DISTINCT f.friendid,
c.clientname AS UserName
FROM users u
INNER JOIN clients c
ON u.id_client = c.id
INNER JOIN friends f
ON f.friendid = u.id) x
ON f1.friendid = x.friendid
INNER JOIN (SELECT DISTINCT f.userid,
c.clientname AS UserName
FROM users u
INNER JOIN clients c
ON u.id_client = c.id
INNER JOIN friends f
ON f.userid = u.id) y
ON f1.userid = y.userid;
我无法在我的工作机器上测试它,因为它被锁定得太紧,我根本无法完成任何工作。