需要访问VBA代码以删除表中的空字段 [英] Need Access VBA code to drop empty fields in a table

查看:91
本文介绍了需要访问VBA代码以删除表中的空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我已将excel文件导入Access表,但该表包含一些空字段,是否有人知道如何使用Access VBA删除这些空字段?


在此先感谢。

Hello everyone, I have imported an excel file into an Access table, but the table contains some empty fields, does anyone know how to delete those empty fields using Access VBA?

Thanks in Advance.

推荐答案

这个有点挑战,但在这里它。以下代码将循环遍历Recordset中的所有Fields,在这种情况下,一个基于Employees表,并将列出到立即窗口''ALL'' ''NO的字段'''ALL''记录集中的记录。要随后删除那些字段会更加棘手,因为您无法对Fields Collection的成员使用Delete方法,并且如果它包含在活动Recordset中,则无法使用SQL,DAO,ADO等删除字段。如果你真的需要这个功能,我相信我可以容纳你,请告诉我。
This one was a little challenging, but here it goes. The following code will loop through all Fields in a Recordset, in this case one based on an Employees Table, and will list to the Immediate Window ''ALL'' Fields which have ''NO'' values in ''ALL'' the Records in the Recordset. To subsequently DELETE those Fields would be even trickier yet since you cannot use the Delete Method on a member of the Fields Collection, and you cannot Delete a Field using SQL, DAO, ADO, etc. if it is contained in an active Recordset. Should you really need this functionality, I''m sure that I can accommodate you, just let me know.
展开 | 选择 | Wrap | 行号



这个有点挑战性,但在这里。以下代码将循环遍历Recordset中的所有Fields,在这种情况下,一个基于Employees表,并将列出到立即窗口''ALL'' ''NO的字段'''ALL''记录集中的记录。要随后删除那些字段会更加棘手,因为您无法对Fields Collection的成员使用Delete方法,并且如果它包含在活动Recordset中,则无法使用SQL,DAO,ADO等删除字段。如果你真的需要这个功能,我相信我可以容纳你,请告诉我。
This one was a little challenging, but here it goes. The following code will loop through all Fields in a Recordset, in this case one based on an Employees Table, and will list to the Immediate Window ''ALL'' Fields which have ''NO'' values in ''ALL'' the Records in the Recordset. To subsequently DELETE those Fields would be even trickier yet since you cannot use the Delete Method on a member of the Fields Collection, and you cannot Delete a Field using SQL, DAO, ADO, etc. if it is contained in an active Recordset. Should you really need this functionality, I''m sure that I can accommodate you, just let me know.
展开 | 选择 | Wrap | 行号



非常感谢您的回复,上面的代码成功显示了我的表中的空字段(ImportedData)。现在我想从表中删除这些空字段。如果我能得到这个代码,那真的会让我感到很开心。


我厌倦了在互联网上搜索这些代码。


谢谢。
Thanks a lot for the reply, the above code successfully displaying the empty fields in my table (ImportedData). Now I would like to delete these empty fields from the table. It would really make my day if I can get this code.

I am tired of searching this code on internet.

Thanks.



要删除的字段的名称必须存储在数组中,必须关闭Recordset,然后必须从数组,以及字段本身已经通过DAO删除,因为我们已经在使用它。存在逻辑,当我有机会时,我会做出''尝试''来实现它。顺便说一句,不要在这个问题上打败自己,因为这是相当专业的,而且不是问题代码。我不认为你会在互联网上找到很多这方面的参考。请在今晚或明天下午回来查看。

The Names of the Fields to Delete would have to be stored in an Array, the Recordset would have to be closed, the Names would then have to be retrieved from the Array, and the Fields themselves deleted via DAO since we are already using it. There lies the logic, when I get a chance I will make an ''attempt'' to implement it. BTW, don''t beat yourself on this one, since this is rather specialized and not-mush-asked-for code. I don''t think that you will find many references to this on the Internet. Check back this evening or at the latest tomorrow afternoon.


这篇关于需要访问VBA代码以删除表中的空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆