sql - 收集选项组值并将值插入表中
问题描述
我有一个带有几个切换按钮的表单。我希望能够为特定值切换每个按钮并将所选值用作insert into
另一个表。
表单输入工作,表格和连接工作,表单子数据表查询是可更新的并显示相关字段
Select * from FRAMEQUERY(as Boolean) WHERE Value = True
INSERT INTO ORDERDETAILS
需要一些代码帮助来收集值并插入它们。
解决方案
由于要插入的字段取决于表单控件的状态,因此您需要遍历相关的表单控件并构造适当的 SQL 语句,然后可以使用DoCmd.RunSQL
或等方法执行该语句CurrentDb.Execute
。
我建议对表单上的控件进行迭代,并且对于每个控件,如果选择了该控件,请将相应的字段名称附加到 SQL 语句的insert into
和select
部分。
例如,在pseudocode中,这可能类似于:
strFld = ""
strVal = ""
for each control on form
if control.value = true then
strFld = strFld & "YourFieldName, "
strVal = strVal & "YourFieldValue, "
end if
next control
if strFld <> "" then
strFld = left(strFld, len(strFld)-2)
strVal = left(strVal, len(strVal)-2)
strSQL = "insert into YourTable (" & strFld & ") values (" & strVal & ")"
end if
推荐阅读
- sublimetext3 - 在 Sublime Text 4 中使用混合空格和制表符缩进
- c# - 自定义编译时版本控制方案和运行时代码更改
- php - 了解使用 Google 登录
- intellij-idea - 如何在 IntelliJ 中创建一个空的 JavaFX 项目
- python - making list index possible for python class list
- docker - Is "docker pull" supposed to re-use already downloaded layers instead of starting from scratch?
- vue.js - How to open component v-file-input, when it is hidden?
- android - How can I get negative radius Android Round Corner with XML
- java - 为什么 Spring Security permitAll 不起作用?
- angular - 为什么即使使用 https、samesite=none 和 secure=true 也不会发送跨站点 cookie