JoshuaAnthony
Registered User.
- Local time
- Today, 21:38
- Joined
- Dec 18, 2003
- Messages
- 68
Hi,
I'm exporting the recordSource of a form to Excel. The recordsource itself is a query but I'd like it to remain unchanged the whole time I have the form open (so that it mirrors the data that I export to excel). So ideally I would like to be able to create a table based on the recordSource query, and set that table to be the new recordSource before exporting the data to Excel. My only problem is with actually creating the table.
I have tried:
Now, I get a run-time error '3011' on DoCmd.OutputTo saying that it can't find the table that I have specified and when I look in tables it doesn't exist but why does the Set tabledef line work (I imagine it doesn't work because I'm creating the tabledef using a query instead of a table but I can't see any other way)?? Does anybody know how you are ACTUALLY supposed to do this?
Thanks,
Joshua
I'm exporting the recordSource of a form to Excel. The recordsource itself is a query but I'd like it to remain unchanged the whole time I have the form open (so that it mirrors the data that I export to excel). So ideally I would like to be able to create a table based on the recordSource query, and set that table to be the new recordSource before exporting the data to Excel. My only problem is with actually creating the table.
I have tried:
Code:
Dim querydef As Object ' For referring to Access query objects
Dim tabledef As Object
strUserQueryName = [Forms]![User Look-up]![Username] & "Query"
strUserTableName = [Forms]![User Look-up]![Username] & "Table"
Set querydef = CurrentDb.CreateQueryDef(strUserQueryName, strSQL)
Set tabledef = CurrentDb.CreateTableDef(strUserTableName, , strUserQueryName)
' Output a snapshot of the query
DoCmd.OutputTo acOutputTable, strUserTableName, acFormatXLS, strUserFileName
Now, I get a run-time error '3011' on DoCmd.OutputTo saying that it can't find the table that I have specified and when I look in tables it doesn't exist but why does the Set tabledef line work (I imagine it doesn't work because I'm creating the tabledef using a query instead of a table but I can't see any other way)?? Does anybody know how you are ACTUALLY supposed to do this?
Thanks,
Joshua