本文介绍了使用VBA插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我为什么INSERT INTO会产生语法错误


Private Sub Command7_Click()

Dim strUSER As String

strUSER = Nz(DLookup([user],table2,[user] =''"& username.Value&"''")," nouser")

如果strUSER =" nouser"然后

INSERT INTO table2;

VALUES(username.Value,password.Value);

MsgBox" User added"

Else

MsgBox" user already exists"

Can someone please tell me why INSERT INTO generates syntax error

Private Sub Command7_Click()
Dim strUSER As String
strUSER = Nz(DLookup("[user]", "table2", "[user] =''" & username.Value & "''"), "nouser")
If strUSER = "nouser" Then
INSERT INTO table2;
VALUES (username.Value,password.Value);
MsgBox "User added"
Else
MsgBox "user already exist"
End If

推荐答案




不幸的是代码生成语法错误:(

Unfortunately the code generated syntax error :(




I尝试过这个


CurrentDb.Execute(" INSERT INTO table2([user],[pass])VALUES(username.value,password.value)")


gener ates:参数太少,期望2


我也试过

CurrentDb.Execute(" INSERT INTO table2([user],[pass])VALUES (''username.value'',''password.value'')")


事情被添加到表格中,而不是用户名我实际获得文本用户名表中的值。


第3次尝试


CurrentDb.Execute(&INSERT INTO table2([user],[pass] ])VALUES(''' &安培; username.value& "","" &安培; password.value& "'''")")


会在第一个时产生错误''"


I tried this

CurrentDb.Execute ("INSERT INTO table2 ([user], [pass]) VALUES (username.value,password.value)")

generates: too few parameters, expect 2

I also tried
CurrentDb.Execute ("INSERT INTO table2 ([user], [pass]) VALUES (''username.value'',''password.value'')")

Things get added to the table but instead the value of username I actualy get the text username.value in the table!!!

3rd attempt

CurrentDb.Execute ("INSERT INTO table2 ([user], [pass]) VALUES ("''" & username.value & "''","''" & password.value & "''")")

would generate error at the first " '' "


这篇关于使用VBA插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:47