用VBA于ACCESS中编程报错:INSERT INTO语句的语法错误
一个西文检索数据库,生成索引代码如下:PrivateSubupdateind_Click()DimsqlAsStringDimconnstrAsStringDimconn...
一个西文检索数据库,生成索引代码如下:
Private Sub updateind_Click()
Dim sql As String
Dim connstr As String
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset 'to connect the database
Dim words 'define the variables needed
Dim Ifulltext As String
Dim Idno As Integer
Dim i As Integer
Dim letter As String
Dim ins As String
Dim delete As String
connstr = "Provider=Microsoft.jet.OleDb.4.0;Persist Security Info=false;Data Source=e:\papersTest.mdb"
Set conn = New ADODB.Connection
conn.Open connstr
Set rst = New ADODB.Recordset
sql = "SELECT * FROM papers "
rst.Open sql, conn, adOpenDynamic, adLockOptimistic
rst.MoveFirst
Do While Not rst.EOF
Ifulltext = LCase(rst("fulltext")) 'switch the uppercase into lowercase
Idno = rst("dno")
i = 1
Do While i <= Len(Ifulltext) 'switch all the punctuation marks to blank
letter = Mid(Ifulltext, i, 1)
If Asc(letter) < Asc("a") Or Asc(letter) > Asc("z") Then
Ifulltext = Replace(Ifulltext, letter, " ")
End If
i = i + 1
Loop
i = 0
words = Split(rst.Fields("fulltext")) 'get each word as a string array
Do While i < UBound(words) '- LBound(words) + 1
If words(i) <> "" Then
ins = "INSERT INTO [ind](qword,dno) VALUES (" & Chr$(34) & words(i) & Chr$(34) & "," & dno & ")" 'insert into the ind
DoCmd.SetWarnings False
DoCmd.RunSQL ins
DoCmd.SetWarnings True
End If
i = i + 1
Loop
rst.MoveNext
Loop
rst.close
为避免关键字已经将index全部改为ind了,但是还是报错,为什么啊?谢谢谢谢了~~~~~ 展开
Private Sub updateind_Click()
Dim sql As String
Dim connstr As String
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset 'to connect the database
Dim words 'define the variables needed
Dim Ifulltext As String
Dim Idno As Integer
Dim i As Integer
Dim letter As String
Dim ins As String
Dim delete As String
connstr = "Provider=Microsoft.jet.OleDb.4.0;Persist Security Info=false;Data Source=e:\papersTest.mdb"
Set conn = New ADODB.Connection
conn.Open connstr
Set rst = New ADODB.Recordset
sql = "SELECT * FROM papers "
rst.Open sql, conn, adOpenDynamic, adLockOptimistic
rst.MoveFirst
Do While Not rst.EOF
Ifulltext = LCase(rst("fulltext")) 'switch the uppercase into lowercase
Idno = rst("dno")
i = 1
Do While i <= Len(Ifulltext) 'switch all the punctuation marks to blank
letter = Mid(Ifulltext, i, 1)
If Asc(letter) < Asc("a") Or Asc(letter) > Asc("z") Then
Ifulltext = Replace(Ifulltext, letter, " ")
End If
i = i + 1
Loop
i = 0
words = Split(rst.Fields("fulltext")) 'get each word as a string array
Do While i < UBound(words) '- LBound(words) + 1
If words(i) <> "" Then
ins = "INSERT INTO [ind](qword,dno) VALUES (" & Chr$(34) & words(i) & Chr$(34) & "," & dno & ")" 'insert into the ind
DoCmd.SetWarnings False
DoCmd.RunSQL ins
DoCmd.SetWarnings True
End If
i = i + 1
Loop
rst.MoveNext
Loop
rst.close
为避免关键字已经将index全部改为ind了,但是还是报错,为什么啊?谢谢谢谢了~~~~~ 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询