我有一个表单,上部分为个人基本信息,下部分用sstab1(学习情况,学费管理,等四项)每项有多条记录,个人基本情况中有25项,学费表单(对同一人最多有8条记录)中有10项,且都有可能修改,现修改记录的思路为先删除原记录后添加新记录。出现情况为删除了旧记录但添加了多条记录且有重复的记录(基本信息表同学费表为一对多)请指教!
我的
‘删除
If rsxf.State = 1 Then
       rsxf.Close
End If
    rsxf.Open "select * from  xf  where 个人学号  = '" & xx & "'", conn, adOpenKeyset, adLockOptimistic  
    If rsxf.RecordCount > 0 Then
      rsxf.Delete
    End If
    rsxf.Close’添加
 rsxf.Open "select * from  xf ", conn, adOpenKeyset, adLockOptimistic  
             If Len("" & Trim(Combo12.Text)) <> 0 Then
                 rsxf.AddNew
                 rsxf.Fields(0).Value = Trim(Text4.Text)
                 rsxf.Fields(1).Value = Trim(Combo12.Text)
                 rsxf.Update
               End If
               If Len("" & Trim(Combo13.Text)) <> 0 Then
                 rsxf.AddNew
                 rsxf.Fields(0).Value = Trim(Text4.Text)
                 rsxf.Fields(1).Value = Trim(Combo13.Text)
                 rsxf.Update
               End If              ........
             
              总共判断8个(块if)Combo.Text中内容是否为空,不空则添加8条修改后的记录,如何做!!!
有人建议用update语句,但问题是有可能新加记录(而非修改已经有的记录)

解决方案 »

  1.   

    '删除
    conn.execute "delete from xf where 个人学号='"& xx &"'"'添加
    If Len("" & Trim(Combo12.Text)) <> 0 Then
        conn.execute "insert into xf(aa,bb) values('"& trim(text4.text) &"','"& trim(combo12.text) &"')"
    end if
    If Len("" & Trim(Combo13.Text)) <> 0 Then
        conn.execute "insert into xf(aa,bb) values('"& trim(text4.text) &"','"& trim(combo13.text) &"')"
    end if
    ...
      

  2.   

    If Len("" & Trim(Combo12.Text)) <> 0 Then
      hj = (Val(Trim(Text11.Text)) + Val(Trim(Text12.Text)) + Val(Trim(Text13.Text)))
      conn.Execute "insert into xf(个人学号,学期,学费,书费,杂费,合计,应缴费用,缴费时间,单据号,欠费) values( '" & Trim(Text4.Text) & "','" & Trim(Combo12.Text) & "','" & Val(Trim(Text11.Text)) & "','" & Val(Trim(Text12.Text)) & "','" & Val(Trim(Text13.Text)) & "','" & hj & "','" & Val(Trim(Text14.Text) & "','" & Trim(Text15.Text) & "','" & Trim(Text102.Text) & "','" & Val(Trim(Text110.Text)) & "')")
    End If
    运行时出现提示语法有误!!
      

  3.   

    看看哪里有错误
    dim strsql as string
    strsql= "insert into xf(个人学号,学期,学费,书费,杂费,合计,应缴费用,缴费时间,单据号,欠费) values( '" & Trim(Text4.Text) & "','" & Trim(Combo12.Text) & "','" & Val(Trim(Text11.Text)) & "','" & Val(Trim(Text12.Text)) & "','" & Val(Trim(Text13.Text)) & "','" & hj & "','" & Val(Trim(Text14.Text) & "','" & Trim(Text15.Text) & "','" & Trim(Text102.Text) & "','" & Val(Trim(Text110.Text)) & "')")
    msgbox strsql
      

  4.   

    leftie:
          您好!
          1,学期,学费,书费,杂费,合计,欠费为数值型
          2,我把你的复过去运行时出现提示语法有误!!
         实时错误‘-214717900(80040e14)’    
         “syntax error in string in query expression ''369'”
      

  5.   

    strsql= "insert into xf(个人学号,学期,学费,书费,杂费,合计,应缴费用,缴费时间,单据号,欠费) values( '" & Trim(Text4.Text) & "'," & cdbl(Combo12.Text) & "," & cdbl(Text11.Text) & "," & cdbl(Text12.Text) & "," & cdbl(Text13.Text) & "," & hj & "," & cdbl(Text14.Text) & ",'" & Trim(Text15.Text) & "','" & Trim(Text102.Text) & "','" & Val(Trim(Text110.Text)) & "')"'如果为数值型,则无需两边的单引号
      

  6.   

    leftie:
          您好!
          为数值型,不要两边的单引号为
    If Len("" & Trim(Combo12.Text)) <> 0 Then
       hj = (Val(Trim(Text11.Text)) + Val(Trim(Text12.Text)) + Val(Trim(Text13.Text)))
       conn.Execute "insert into xf(个人学号,学期,学费,书费,杂费,合计,应缴费用,缴费时间,单据号,欠费) values( '" & Trim(Text4.Text) & "','" & Trim(Combo12.Text) & "'," & Val(Trim(Text11.Text)) & " ," & Val(Trim(Text12.Text)) & "," & Val(Trim(Text13.Text)) & "," & hj & "," & Val(Trim(Text14.Text) & ",'" & Trim(Text15.Text) & "','" & Trim(Text102.Text) & "'," & Val(Trim(Text110.Text)) & ")")           
    End If     实时错误‘-214717900(80040e14)’    
         “number or query  values and destination fields are not the same ”