Executing SQL updates on linked Excel table in Access

自闭症网瘾萝莉.ら 提交于 2019-12-12 16:13:59

问题


Using Access 2010, I imported several Excel tables into Access, and built forms that allowed the user to update and add information to the tables. The forms work by dynamically generating SQL alter and update statements in VBA and then running DoCmd.RunSQL. However, I wanted the changes to the tables to be reflected in the original Excel tables so I deleted the tables in Access, and instead linked the Excel tables to Access.

All of my select queries continue to work so I am able to access the data in essentially the same way, but I am not able to execute SQL statements on the tables in VBA using DoCmd.RunSQL, which means I can't perform the SQL update and alter statements like I did before.

My question is: can I execute SQL including alter and update statements on my linked Excel tables, and if so, how?


回答1:


can I execute SQL including alter and update statements on my linked Excel tables?

No, the linked worksheets are read-only from Access' perspective. That is not just a limitation for Access SQL. If you open one of those links directly in Datasheet View, you can not alter stored values, delete rows, or add new rows.

Microsoft explains ...

Because of legal issues, Microsoft has disabled the functionality in Access 2003 and in Access 2002 that let users change the data in linked tables that point to a range in an Excel workbook.

That edit capability was removed with Access 2002 and 2003, and not added back to subsequent Access versions.

See the linked page for further details, including their suggested workaround.




回答2:


You have an easy option. If you link the Excel file(s), you can then create a make table query using the linked Excel table. After the new table is created, you now have Access data which you can manipulate to your liking. You can then export new, updated, or changed data it back to Excel if needed.

Keep in mind, when working with external data, you need to get a little more exotic in your methods to access and manipulate that data.



来源:https://stackoverflow.com/questions/34932034/executing-sql-updates-on-linked-excel-table-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!