Why does this SQL statement ask for a value?

本秂侑毒 提交于 2019-12-12 01:38:02

问题


I have a form which lets you add names to the table and shows it in a dropdown menu. When I click on the form, it should ask the user to enter the name they would like to add and click "ok". Once the user clicks ok, the name should be stored in a table and added to the drop-down menu.

Every thing works fine but when the user types the value in the textbox and clicks "ok" a window pops up asking for the parameter value. Whatever the user types in this parameter value gets saved in the table instead of getting the value from the textbox. I am not sure why this happens.

Name is a string, is it the quatation marks?

Here is the code:

Dim test As String
test = Text1.Value
DoCmd.RunSQL "INSERT INTO List_Of_Agencies(T_PI_GroupName)VALUES (" & test & ");"
Form_0_Cover.Combo2.Requery

回答1:


DoCmd.RunSQL "INSERT INTO List_Of_Agencies(T_PI_GroupName) VALUES ('" & test & "')"


来源:https://stackoverflow.com/questions/11210605/why-does-this-sql-statement-ask-for-a-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!