根据表单中选择的字段构建查询 [英] Building Query based on fields selected in a form

查看:69
本文介绍了根据表单中选择的字段构建查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我最近的任务是接管一堆我没有创建的Access数据库。我的VBA技能很难说最好,但我有一个特别的问题,我正在努力。我想要做的是使用一个表单来识别将通过查询并生成拆分字段的Excel文档的多个值。我已经有了代码,但我需要添加一个列选择。要添加的工具或

Hi Everyone, I have recently been tasked with taking over a bunch of Access databases that I didn''t create. My VBA skills are weak to say the best but I have a particular problem I am working on. What I want to do is use a form to identify multiple value that will pass through a query and generate excel documents for a split field. I already have the code for that but I need to add a "column selection" tool to add or

展开 | 选择 | Wrap | 行号

推荐答案

  1. 根据我的收集,您决定包含/省略查询中的列是由一系列复选框决定的。基于此,我们假设我们有一个名为Table1的表,其中包含三个字段:
  1. From what I can gather, your decision to include/omit Columns from a Query is determined by a series of Check Boxes. Based on this, let''s assume we have a Table named Table1 with three Fields:
  1. [First] {TEXT}
  2. [MI] {TEXT}
  3. [Last] {TEXT}

  • 对于您可能希望包含在查询中的所有字段,请创建一个表格上的复选框。这个复选框的名称将是chk& [字段名称]。我假设表单上唯一的复选框是表示可能/可能不包含在您的查询中的字段的复选框。
  • 复制-N-在适当的地方粘贴以下代码。代码将:

  • For all the Fields you may wish to include in your Query, create a Check Box on your Form. The Name of this Check Box will be chk & [Field Name]. I''m assuming that the only Check Boxes on the Form are those representing Fields which may/may not be included in your Query.
  • Copy-N-Paste the following Code wherever appropriate. The Code will:

    1. 循环通过表单上的所有控件。
    2. 如果控件是复选框并且已选中,将开始构建SQL语句。
    3. 一旦处理了表单上的所有控件,将修剪SQL语句并构建Final Statement并将其分配给Variable strSQLFinal。
    4. 如果没有选中Check Box,则代码无害地存在。

    展开 | 选择 | Wrap | 行号


    感谢您的快速回复。我试图弄清楚你之前曾帮助过某个人的帖子,但却无法确切知道这会发生什么。我在哪里声明尺寸是否重要?此外,表单有4个文本框,也通过查询传递变量。所以我不确定这将如何添加到我现有的代码中:

    Thanks for the quick response. I was trying to make sense of a previous post that you had helped someone with but can''t figure out exactly where this would go. Does it matter where I declare the dimensions? Also, the form has 4 text boxes that also pass variables through the query. so I''m not sure how this would be added to my existing code:

    展开 | 选择 | Wrap | 行号


    1. 构建逗号分隔的字符串(第7行到第15行)并将其传递给函数(第22行):
    1. Build a Comma Delimited String (Lines 7 to 15) and pass it to a Function (Line 22):
    展开 | 选择 | Wrap | 行号


    这篇关于根据表单中选择的字段构建查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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