简体   繁体   English

MS Access筛选器表单结果使用复选框

[英]MS Access Filter Form Results Using Checkboxes

I have a single table with contact info and about 25 checkboxes. 我有一张包含联系方式的表格和约25个复选框。 I have a form to input the contact info, and almost all the checkboxes are to specify which power tool was purchased, with the last two checkboxes specifying whether marketing should come via US Mail or Email. 我有一个用于输入联系信息的表格,几乎所有复选框都用于指定购买的电动工具,最后两个复选框用于指定是通过美国邮件还是通过电子邮件进行营销。

My end-game is to have a CSV file containing the name, address, and email of a subset of all the records. 我的最终结果是拥有一个CSV文件,其中包含所有记录的子集的名称,地址和电子邮件。 Which records go in is simple: if I check "chainsaw" and "email", then everyone who didn't buy a chainsaw AND want email communication is filtered out. 输入哪些记录很简单:如果我勾选“电锯”和“电子邮件”,那么所有未购买电锯并希望电子邮件通信的人都会被过滤掉。 If I check "chainsaw" and "weedwacker" and "US mail" I want all records who bought EITHER a chainsaw OR a weedwacker OR both AND want US mail communications. 如果我勾选“链锯”,“ weedwacker”和“美国邮件”,我希望所有购买了电锯或杂草或两者兼有并希望与美国进行邮件通讯的记录。

I envision using a form with checkboxes where checking any box filters the records to only include those records where that checkbox = yes in the table (for the power tools), and the mail or email filters it further, and then to generate a query that contains those records, then export as a CSV. 我设想使用带有复选框的表单,其中选中任何复选框都会过滤记录,以仅包括那些在表中(对于电动工具而言)checkbox = yes的记录,然后邮件或电子邮件对其进行进一步过滤,然后生成一个查询包含这些记录,然后导出为CSV。

My Google-ing skills are good, my VBA coding skills are nonexistent (I'm an HTML/CSS/Joomla guy but got handed this mini project), and the results of searching Google and stackoverflow have yielded nothing that would guide me in the right direction. 我的Google-ing技能很好,我的VBA编码技能不存在(我是HTML / CSS / Joomla家伙,但是得到了这个迷你项目),并且搜索Google和stackoverflow的结果并没有任何指导我正确的方向。

I know the table structure is not optimal, but it is manageable for the person I'm making it for who would struggle with more than one table in Access. 我知道表结构不是最佳的,但是对于我要使它在Access中处理多个表的人来说是可以管理的。 And it's based off of some archaic database software and they want the structure to stay the same. 它基于一些古老的数据库软件,他们希望结构保持不变。

You will need to build a sql statement in your code. 您将需要在代码中构建一个sql语句。 It can start with: 它可以开始于:

sql = "select * from MyTable where ID > 0" 'the "Where ID > 0" is here so the remaining sql additions can all say AND sql =“从MyTable的ID> 0处选择*”'此处的“ Where ID> 0”在这里,因此其余的sql附加项都可以说AND

then have a series of if statments that will add to the sql statement: 然后有一系列的if语句将添加到sql语句中:

if chkChainsaw = -1 then 如果chkChainsaw = -1,则
sql = sql & " AND Chainsaw = 1" sql = sql&“ AND电锯= 1”
end if 万一
if chkweedwacker = -1 then 如果chkweedwacker = -1,则
sql = sql & " AND weedwacker= 1" sql = sql&“ AND weedwacker = 1”
end if 万一

When you are done building your sql statement, you can build a recordset and export a csv file from that. 构建完sql语句后,可以构建记录集并从中导出csv文件。

dim rs as recordset 作为记录集的rs
set rs = currentdb.openrecordset(sql, dbopendynaset) 设置rs = currentdb.openrecordset(sql,dbopendynaset)
do while not rs.eof 做而不是做事
'export data '出口数据
rs.movenext rs.movenext
loop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM