Access VBA 报表未绑定文本框及复选框的分情况计算问题?

问题出在了这两句赋值上:

Me.考勤天数.Value = day_count
Me.Controls("Check_" & i) = True

程序是根据报表的记录逐条分4种情况进行判断,然后对考勤天数和每条的Checkbox进行画√。但以上两句的调用结果只是将每个人的情况都赋值一遍,最终结果等于最后一个人的情况。

请问如何破这个问题?
图片说明

图片说明
图片说明

Private Sub 考勤计算_Click()

Dim year_in As Integer
Dim year_n As Integer
Dim year_out As Integer
Dim month_in As Integer
Dim month_n As Integer
Dim month_out As Integer
Dim day_count As Integer
Dim day_n As Integer



Dim i As Integer

Dim p As Integer



Dim FD As Date
Dim LD As Date


year_n = Format(Date, "yyyy")

month_n = Format(Date, "mm")

day_n = Format(Date, "dd")


FD = DateSerial(year(Date), Month(Date), 1)

LD = DateSerial(year(Date), Month(Date) + 1, 0)



'从第一条记录到最后一条记录

Dim db
Dim rs As Recordset
Dim din As Date
Dim dou As Date

Set db = CurrentDb
Set rs = db.OpenRecordset("select * from [RS-T10-考勤休假信息] where(([是否休假]=False) AND ([是否结束]=False))")

rs.MoveFirst


'DoCmd.GoToRecord , , acFirst

If Not rs.EOF Then

Do While Not rs.EOF

'-------------------------------------------------------
'输入每一条记录应该执行的动作


'判断入场及离场是否填入数据

If IsNull(rs.Fields("入场日期")) = False Then

din = rs.Fields("入场日期")

year_in = Format(din, "yyyy")

month_in = Format(din, "mm")

End If


If IsNull(rs.Fields("实际离场")) = False Then

dou = rs.Fields("实际离场")

year_out = Format(dou, "yyyy")

month_out = Format(dou, "mm")

End If



'情况1 如果当月进场 则考勤天数等于 当月最后一天 - 入场日期

If year_in = year_n And month_in = month_n And (year_out > year_n Or month_out > month_n) Then


day_count = LD - din + 1


MsgBox "入场日期" & Format(din, "d")

MsgBox "本月最后一天" & Format(LD, "dd")


For i = Format(din, "d") To Format(LD, "dd")

**Me.Controls("Check_" & i) = True**_

Next i

MsgBox "MichaelWZ: 欢迎该同志入场!"

End If



'情况2 如果当月离场 则考勤天数等于 离场日期 - 当月第一天

If (year_in < year_n Or month_in < month_n) And year_out = year_n And month_out = month_n Then

day_count = dou - FD + 1



MsgBox "本月第一天" & Format(FD, "d")

MsgBox "离场日期" & Format(dou, "dd")


For i = Format(FD, "dd") To Format(dou, "dd")

**Me.Controls("Check_" & i) = True**

Next i

MsgBox "MichaelWZ: 欢送该同志离场!"

End If


'情况3 如果当月进场 并且 当月离场 则考勤天数等于 离场日期-入场日期

If year_in = year_n And month_in = month_n And year_out = year_n And month_out = month_n Then

day_count = dou - din + 1



MsgBox "入场日期" & Format(din, "d")

MsgBox "离场日期" & Format(dou, "dd")


For i = Format(din, "dd") To Format(dou, "dd")

**Me.Controls("Check_" & i) = True**

Next i

MsgBox "MichaelWZ: 违反休假制度,该同志可能是开除了!"


End If


'情况4 正常在场 则考勤天数等于 当月最后一天 - 当月第一天

If (year_in < year_n Or month_in < month_n) And (year_out > year_n Or month_out > month_n) Then

day_count = LD - FD + 1



MsgBox "第一天" & Format(FD, "d")

MsgBox "最后一天" & Format(LD, "dd")


For i = Format(FD, "dd") To Format(LD, "dd")

**Me.Controls("Check_" & i) = True**

Next i

MsgBox "MichaelWZ: 祝贺 " & rs.Fields("员工编号") & " 同志全勤!"

End If



**_Me.考勤天数.Value = day_count_**



'释放变量


year_in = 0
month_in = 0
year_out = 0
month_out = 0
day_count = 0




'--------------------------------------------------------
rs.MoveNext

Loop

End If

rs.Close

Me.本月天数.Value = Format(LD, "dd")
year_n = 0
month_n = 0
day_n = 0
i = 0
FD = 0
LD = 0

End Sub

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问