Public Sub CalcDaysWorked()
Dim I As Integer
For I = 41 To (LastClickedOn) Step -1 'count backwards valid day worked must be after infraction
If ((Val(FrmCalendar.TxtDate(LastClickedOn).Text = "1")) Or (Val(FrmCalendar.TxtDate(LastClickedOn).Text = "2")) Or _
(Val(FrmCalendar.TxtDate(LastClickedOn).Text = "3")) Or (Val(FrmCalendar.TxtDate(LastClickedOn).Text = "7"))) Then
FrmCalendar.TxtDaysWrkd.Text = "0" 'RESTART "W" COUNT
Else
If ((Val(FrmCalendar.TxtDate(LastClickedOn).Text <> "1")) And (Val(FrmCalendar.TxtDate(LastClickedOn).Text <> "2")) Or _
(Val(FrmCalendar.TxtDate(LastClickedOn).Text <> "3")) And (Val(FrmCalendar.TxtDate(LastClickedOn).Text <> "7"))) Then
I = (I - 1) 'IGNORE THE ENTRY
Else
If FrmCalendar.TxtDate(LastClickedOn).Text = "W" Then
FrmCalendar.TxtDaysWrkd.Text = (Val(FrmCalendar.TxtDaysWrkd.Text + 1))
Exit Sub
End If
End If
End If
Next I
End Sub
Explanation:
Ive 41 textboxes on my form called TxtDate.text
I have to keep track of the following:
Points for employee--(can be a 1,2,3 or 7)
Days worked for employee (my w's)
AND some miscelaneous stuff which I need to ignore for this code
For days worked (my w's)
I need to keep track of how many w's there are on my form for a given month
Every time an employee gets a point (a 1,2,3 or 7)
My days worked(w's) must go back to zero
I only want the w's to be calulated after an employees point was added
My code above works 100% UNLESS
a user goes back and changes a TxtDate.text value
Youll notice Im counting my 41 textboxes backwards for this reason
AND the LastCLickedOn variable refers to the last TxtDate textbox when
a user entered a point of 1,2,3 or 7 for an employee
I must allow the user to change a value so setting enable to false is not an option
....Thanks Greg!