sql - How to pass variables from VBA through SQL?
问题描述
I'm trying to pass values from a Form into my database, via SQL:
Private Sub Befehl4_Click()
Dim SQL As String
Dim unique As String
unique = Forms!frm_test!PN
SQL = "INSERT INTO tab_test (Feld1) VALUES (unique)"
DoCmd.RunSQL SQL
End Sub
When I execute this code from my button in my Form, unique
isn't passed to the SQL-command. I have to type it in. When writing the SQL-command this way:
SQL = "INSERT INTO tab_test (Feld1) VALUES (Forms!frm_test!PN)"
It works how expected.
What am I missing or doing wrong?
解决方案
SQL = "INSERT INTO tab_test (Feld1) VALUES ('" & Forms!frm_test!PN & "')"
推荐阅读
- angularjs - 通过单向绑定传递数据到 md 对话框
- time-series - 在遗传算法中改变符号表达式树的最佳方法
- ios - Xcode 11.4 未生成自定义意图类
- uwp - 现代应用程序的注册表功能
- python-3.x - 将 create_api.sh 移植到 python 脚本
- delphi - 自定义组件中的持久二进制数据
- linux - Docker 安装在 linux 中失败并出现错误 [Errno 14] HTTPS 错误 404 - 未找到
- python - 正在测试的模型名在 Django 中未定义错误
- reactjs - 输入缺少对每个更改的关注
- redis - Redis,实时用例