run-time erroe 3131 FROM子句语法错误
[
sql = "select * from " & tname & "where id=" & "'" & Textid.Text & "'"
Set rec = db.OpenRecordset(sql)
]
tname已经定义 数据库已经连接好了 
声明
Dim sql As String
Dim rec As Recordset
Dim str As String
Dim tname As String
Dim ws As Workspace
Dim db As Database
rec和db已经定义
这个是我添加新记录的一部分完整如下
If Textid.Text <> "" Then
sql = "select * from " & tname & "where id=" & "'" & Textid.Text & "'"
Set rec = db.OpenRecordset(sql)
If rec.EOF Then
'判断rec是否为空
rec.AddNew
'加入数据项
rec.Fields(1).Value = Textname.Text
rec.Fields(2).Value = Textcar.Text
If Text4.Text = "" Or Text5.Text = "" Then
MsgBox "还有其它项目没有填写完毕,请填写!", , "错误!"
Exit Sub
Else
rec.Fields(4).Value = CInt(Text4.Text)
rec.Fields(5).Value = CCur(Text5.Text)
rec.Fields(6).Value = CCur(Text6.Text)
End If
rec.Fields(3).Value = Text3.Text
rec.Update
MsgBox ("添加成功!")
Else
MsgBox ("记录已经存在!")
End If
Textname.Text = ""
Textcar.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End If

解决方案 »

  1.   

    改为"select * from tname where id=" & "'" & Textid.Text & "'"
    行吗?
    “&tname&“是什么?
      

  2.   

    tname后边、where前边少了一个空格,变成了select * from tnamewhere id=...
      

  3.   

    改成 sql = "select * from  " & tname & " where id=" & "'" & Textid.Text & "'"说FROM子句语法错误
    Set rec = db.OpenRecordset(sql)tanme是表格名字 定义好的变量   数据库成功连接
      

  4.   

    sql = "select * from " & tname & "where id=" & "'" & Textid.Text & "'"
                                     ^少一个空格    ^id应该不用'',除非你的数据库定义
      

  5.   

    sql = "select * from " & tname & " where id=" & chr(34) & Textid.Text & chr(34)
    试试