其实我的意思很简单
就是
If Trim(rs2.Fields("type1")) = Right(zyfp1_type, 5) Then
      getTime
  end if
  If Trim(rs2.Fields("type2")) = Right(zyfp1_type, 5) Then
      getTime
  end if
  If Trim(rs2.Fields("type3")) = Right(zyfp1_type, 5) Then
      getTime
  end if
  If Trim(rs2.Fields("type4")) = Right(zyfp1_type, 5) Then
      getTime
  end if
而过程getTime中要处理的不同点就是判断type1,type2,type3,type4中哪一个
等于变量Right(zyfp1_type, 5),如type2=Right(zyfp1_type, 5),则
itemx.SubItems(8) = itemx.SubItems(8) & "," & rs2.Fields("type2") & "(" & mac_time & ")" '注意这里的type2
同理,如type3成立,则为
itemx.SubItems(8) = itemx.SubItems(8) & "," & rs2.Fields("type3") & "(" & mac_time & ")" '注意这里的type2

解决方案 »

  1.   

    我写的代码,看看吧。 ^_^rs2.open "select pay_id,type1,type2,type3,type4 from payment where..."With Rs2
      Do While not .Eof
        '
        ' 对 Type1...Type4 进行验证
        '
        For i = 1  to 4
          If Trim(.Fields("Type" + CStr(i)).Value & "") = Right(zyfp1_type, 5) Then
            '
            ' 调用过程
            '
            GetTime Trim(Fields("pay_id").Value & ""),  Trim(Rs2.Fields("Type" + CStr(i)).Value & "")
          End If
        Next  
        .MoveNext
      Loop
    End With
      ' ------------------------------------------------------------------------------------
    ' 作用:
    '    获得相关时间
    ' 参数:
    '    PayID          String    查找的 ID 号
    '    FieldValues    String    字段值
    '
    ' 编写:Cityhunter([email protected])
    ' 日期:2002-10-19 9:44
    ' 版本:1.0
    ' ------------------------------------------------------------------------------------
    Private Sub GetTime(ByVal PayID as String , ByVal FieldValues as String)
     
      Dim strMac_time  as String    ' 临时存放 字段 strMac_time 值
      
      '
      ' 查找 
      '
      Rs3.Open "SELECT mac_time ' _
             & "FROM machine ' _
             & "WHERE pay_id ='" & Replace(Trim(PayID),"'","''") & "'",
             cn, adOpenStatic
      '
      ' 处理结果
      '
      With Rs3
        Do While not .Eof
          strMac_time = Trim(Fields("mac_time").Value & "")
          
          If (strMac_time >= DTPStart.Value) And _
               (strMac_time <= DTPEnd.Value) Then
            '
            ' 向 itemx 增加
            '    
            itemx.SubItems(8) = itemx.SubItems(8) & "," _
                              & Trim(FieldValues) _
                              & "(" & strMac_time & ")"
          End If
          .MoveNext
        Loop
      End With  
    End Sub
      

  2.   

    好吧,看看OK,不OK,
    rs2.open "select pay_id,type1,type2,type3,type4 from payment where..."
    with rs2
     if not  .eof then
       .movefirst
       do while not .eof
             for i=0 to  .Fields.Count-1   'i是自己声名一个变量
               if Trim(.Fields(i)) = Right(zyfp1_type, 5) then getTime
             next i 
       .movenext
       loop
     end if 
    end with
    rs2.close
      

  3.   

    既然:If Trim(rs2.Fields("type1")) = Right(zyfp1_type, 5) Then
    ...    
    itemx.SubItems(8) = itemx.SubItems(8) & "," & rs2.Fields("type1") & "(" & mac_time & ")" 
    ...
      end if
      If Trim(rs2.Fields("type2")) = Right(zyfp1_type, 5) Then
    ...
         itemx.SubItems(8) = itemx.SubItems(8) & "," & rs2.Fields("type2") & "(" & mac_time & ")" 
    ...
      end if
    .......,那和:If Trim(rs2.Fields("type1")) = Right(zyfp1_type, 5) Then
    ...    
    itemx.SubItems(8) = itemx.SubItems(8) & "," & Right(zyfp1_type, 5)& "(" & mac_time & ")" 
    ...
      end if
      If Trim(rs2.Fields("type2")) = Right(zyfp1_type, 5) Then
    ...
         itemx.SubItems(8) = itemx.SubItems(8) & "," & Right(zyfp1_type, 5) & "(" & mac_time & ")" 
    ...
      end if
    ......有什么区别?假设:type1至type4 有可能相同,则:
    rs2.open "select pay_id,type1,type2,type3,type4 from payment where..."
    for x=0 to rs2.recordcount-1
        i=0
        for j=1 to 4
            If Trim(rs2.Fields("type"& j")) = Right(zyfp1_type, 5) Then
                i=i+1
            end if
        next 
        pay_id = Trim(rs2.Fields("pay_id"))    rs3.Open "select mac_time from machine where pay_id='" & pay_id & "' and mac_time >= " & DTPStart.Value & " and mac_time <= " DTPEnd.Value , cn, adOpenStatic    If rs3.RecordCount <> 0 Then
            For y = 0 To rs3.RecordCount - 1            for j= 1 to i
                    itemx.SubItems(8) = itemx.SubItems(8) & "," _
                              & Right(zyfp1_type, 5) _
                              & "(" & strMac_time & ")"
                next
            next
        end if
    next
    ......如果type1--type4不可能相同,就更简单了:
    rs2.open "select pay_id,type1,type2,type3,type4 from payment where..."
    for x=0 to rs2.recordcount-1
        pay_id = Trim(rs2.Fields("pay_id"))    rs3.Open "select mac_time from machine where pay_id='" & pay_id & "' and mac_time >= " & DTPStart.Value & " and mac_time <= " DTPEnd.Value , cn, adOpenStatic    If rs3.RecordCount <> 0 Then
            For y = 0 To rs3.RecordCount - 1            itemx.SubItems(8) = itemx.SubItems(8) & "," _
                              & Right(zyfp1_type, 5) _
                              & "(" & strMac_time & ")"
            next
        end if
    next
    .....
      

  4.   

    前面漏了一句:mac_time = Trim(rs3.Fields("mac_time"))