刚才漏了一段
Dim conn As New ADODB.Connection
Dim ConnString As String
Dim sql As String
Dim rs As New ADODB.Recordset
Dim QueryMonth As Date '自定义日期
Dim StartMonth As Date '月份第一天
Dim Num As Integer '员工编号
If e.DataRow("审核") = False And e.DataCol.Name = "编号" Then
If e.DataCol.Name= "日期" Or e.DataCol.Name= "编号"
C
If conn.state <> 1 Then
conn.Open (ConnString)
End If
Num=e.DataRow("编号")
QueryMonth=e.DataRow("日期")
StartMonth=CStr(Year(QueryMonth)) & "-" & CStr(Month(QueryMonth)) & "-1"
sql="select * from 合同记录 A where A.[编号]="& num & " And A.[登记月份]<=#" & QueryMonth & "# And (A.[辞退日期] Is null Or A.[辞退日期] >=#" & startmonth & "#) And A.[登记月份]=(Select max(合同记录.[登记月份]) As 登记月份 from 合同记录 where 合同记录.[编号]=" & num & " and 合同记录.[登记月份]<=#" & QueryMonth &"#)"
rs.Open (sql, conn,1,1)
If rs.RecordCount<>0
e.DataRow("姓名")=rs.Fields("姓名").Value
e.DataRow("部门")=rs.Fields("部门").Value
e.DataRow("班组")=rs.Fields("班组").Value
e.DataRow("基本工资")=rs.Fields("基本工资").Value
e.DataRow("月度考核")=rs.Fields("月度考核").Value
e.DataRow("公积金")=rs.Fields("公积金").Value
e.DataRow("社会保险")=rs.Fields("社会保险").Value
e.DataRow("独生费")=rs.Fields("独生费").Value
End If
End If
rs.Close()