以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  对比问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=128232)

--  作者:nxqtxwz
--  发布时间:2018/12/1 17:24:00
--  对比问题
请问老师,我有两个表,其中表A中的出差人列的内容是不固定数目的人姓名,每个名字用“,”隔开;在表B中有姓名列和住址列两列。我想每次表A中的出差人列填写完后都与表B中的姓名列对比,如果表A出差人列的人名中在表B中的住是银川,就产生住宿费,否则不产生,代码怎么写呢?
 表A          表  B  
   张三,李四,王五        张三    银川
           李四    天津
           王五    上海

--  作者:有点蓝
--  发布时间:2018/12/1 17:34:00
--  
表A ,datacolchanged事件

If e.DataCol.name = "出差人" AndAlso e.newvalue > "" Then
    Dim dr As DataRow = DataTables(“B”).Find("住址=\'银川\' and 姓名 in (\'" & e.newvalue.replace(",","\',\'") & "\')")
    If dr IsNot Nothing Then
        msgbox("产生住宿费")
    End If
End If

--  作者:nxqtxwz
--  发布时间:2018/12/3 11:53:00
--  

为什么编译通不过呢?

 

If  Tables("出差记录").Current("出差地点") Like "小坝"  And   Tables("出差记录").Current("出差天数") > 0.5
    If e.DataCol.name = "出差人" AndAlso e.newvalue > "" Then
        Dim dr As DataRow = DataTables("职工信息总表").Find("小坝住房 = True and 姓名 in (\'" & e.newvalue.replace(",","\',\'") & "\')")
        If dr IsNot Nothing Then
            msgbox("不产生住宿费")
        End If
    End If
End If


--  作者:有点甜
--  发布时间:2018/12/3 13:04:00
--  

Dim r = Tables("出差记录").Current

If  r("出差地点") Like "小坝"  And r("出差天数") > 0.5
    If r("出差人") > "" Then
        Dim dr As DataRow = DataTables("职工信息总表").Find("小坝住房 = True and 姓名 in (\'" & r("出差人").replace(",","\',\'") & "\')")
        If dr IsNot Nothing Then
            msgbox("不产生住宿费")
        End If
    End If
End If


--  作者:nxqtxwz
--  发布时间:2018/12/3 14:11:00
--  

红色的行代码还是通不过编译。另出差人也不一定是三个人,人数不固定,有时多,有时少。能对比吗。

 

Dim r = Tables("出差记录").Current

If  r("出差地点") Like "小坝"  And r("出差天数") > 0.5
    If r("出差人") > "" Then
        Dim dr As DataRow = DataTables("职工信息总表").Find("小坝住房 = True and 姓名 in (\'" & r("出差人").replace(",","\',\'") & "\')")
        If dr IsNot Nothing Then
            msgbox("不产生住宿费")
        End If
    End If
End If


--  作者:有点甜
--  发布时间:2018/12/3 15:26:00
--  
我测试,没问题。
--  作者:nxqtxwz
--  发布时间:2018/12/3 15:48:00
--  

老师,我找到问题了,我前面还有一段代码,相互干扰。谢谢你。

但这段代码没有反应,没有起到想要结果。


--  作者:有点甜
--  发布时间:2018/12/3 16:18:00
--  

如果写到datacolchanged事件,代码这样测试。

 

msgbox(123)
If e.DataCol.name = "出差人" AndAlso e.newvalue > "" Then    
    msgbox(456)    
    If  e.DataRow("出差地点") Like "*小坝*"  And e.DataRow("出差天数") > 0.5        
        msgbox(789)
        Dim dr As DataRow = DataTables("职工信息总表").Find("小坝住房 = True and 姓名 in (\'" & e.newvalue.replace(",","\',\'") & "\')")
        If dr IsNot Nothing Then
            msgbox("不产生住宿费")
        End If
    End If
End If


--  作者:nxqtxwz
--  发布时间:2018/12/3 16:43:00
--  
以下是引用有点甜在2018/12/3 16:18:00的发言:

如果写到datacolchanged事件,代码这样测试。

 

msgbox(123)
If e.DataCol.name = "出差人" AndAlso e.newvalue > "" Then    
    msgbox(456)    
    If  e.DataRow("出差地点") Like "*小坝*"  And e.DataRow("出差天数") > 0.5        
        msgbox(789)
        Dim dr As DataRow = DataTables("职工信息总表").Find("小坝住房 = True and 姓名 in (\'" & e.newvalue.replace(",","\',\'") & "\')")
        If dr IsNot Nothing Then
            msgbox("不产生住宿费")
        End If
    End If
End If

老师你好,想写在BeforeSaveDataRow事件中。

[此贴子已经被作者于2018/12/3 16:46:01编辑过]

--  作者:有点甜
--  发布时间:2018/12/3 16:51:00
--  

那就改成

 

    msgbox(456)   
    If  e.DataRow("出差地点") Like "*小坝*"  And e.DataRow("出差天数") > 0.5       
        msgbox(789)
        Dim dr As DataRow = DataTables("职工信息总表").Find("小坝住房 = True and 姓名 in (\'" & e.DataRow("出差人").replace(",","\',\'") & "\')")
        If dr IsNot Nothing Then
            msgbox("不产生住宿费")
        End If
    End If