欲把窗体上四个文本框text1,text2,text3,text4中的文本作为一条记录写入一个access数据表用:
1    Dim ws As Workspace
2     Dim db As Database
3     dim strsql as string
4     dim str1 as string
5     Set ws = DBEngine.Workspaces(0)
6     Set db = ws.OpenDatabase(App.Path & "\pass", False, False, "ms      access;pwd=")
7     str1 = Text1.Text & "," & Text2.Text & "," & text3.Text & "," & Text4.Text
8     strsql="insert into passtable(user,userchinese,pass,qx) values('" & str1 & "')"
9      db.Execute strsql
提示:查询值的数目与目标字段中的数目不同.请问高手:是不是第7行和第8行错误,该怎么改?谢谢.

解决方案 »

  1.   

    7     str1 = Text1.Text & "','" & Text2.Text & "','" & text3.Text & "','" & Text4.Text
      

  2.   

    7     str1 = replace(trim(Text1.Text),"'","’") & "','" & trim(Text2.Text) & "','" & trim(text3.Text) & "','" & trim(Text4.Text)
      

  3.   

    str1 = Text1.Text & "','" & Text2.Text & "','" & text3.Text & "','" & Text4.Text
      

  4.   

    str1 = Text1.Text & "','" & Text2.Text & "','" & text3.Text & "','" & Text4.Text这样肯定是错的~~~最起码应该这样:str1 = Text1.Text & "','" & Text2.Text & "','" & text3.Text & "','" & Text4.Text & "'"呵呵~
      

  5.   

    str1 = "'" & Text1.Text & "','" & Text2.Text & "','" & text3.Text & "','" & Text4.Text & "'"还要保证字段与之相配。若为数值型,便不能加引号了.日期型最好将 "'" 改为"#"
      

  6.   

    在程序中要少用:insert into Table ... values ... 的语句
    要采用:
    .Addnew
    .Field..
    .update
    的方式