S
Shawn
I am creating an Access database to track actions in an office. I have four
fields that have a pop-up calendar appear, allowing a date in, two
re-assignment dates, and a date out to be assigned (the language for the
calendar and populating those fields is the first six sets of code below, and
works fine). The seventh piece of code is supposed to calculate the number
of elapsed work days between the DateIn and DateOut when you click in that
field. This code calculates correctly; however, when I populate the
DaysElapsed field it simultaneously changes the DateIn field date to one day
after the DateOut field.
1. Can anyone please tell me what I need to do so the DateIn field does not
change when the calculation occurs?
2. Is there a better way (than clicking the DaysElapsed field) to populate
the DaysElapsed field with the calculated integer when I enter the date in
the DateOut field? (The perfect solution would be if the calculation would
run when I populate the DateOut field with a date and the DaysElapsed field
would be populated with the calculated integer.)
Thanks for any assistance. The visual basic language from the database
follows:
Option Compare Database
Dim cboOriginator As ComboBox
Private Sub Calendar4_Click()
cboOriginator.Value = Calendar4.Value
cboOriginator.SetFocus
Calendar4.Visible = False
Set cboOriginator = Nothing
End Sub
Private Sub Ctl1stReassignmentDate_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Set cboOriginator = Ctl1stReassignmentDate
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub Ctl2ndReassignmentDate_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Set cboOriginator = Ctl2ndReassignmentDate
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub DateIn_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = DateIn
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub DateOut_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = DateOut
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub DaysElapsed_Click()
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [Date] FROM tblHolidays", dbOpenSnapshot)
DateIn = DateIn + 1
intCount = 0
Do While DateIn <= DateOut
rst.FindFirst "[Date] = #" & DateIn & "#"
If Weekday(DateIn) <> vbSunday And Weekday(DateIn) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
DateIn = DateIn + 1
Loop
DaysElapsed = intCount
End Sub
fields that have a pop-up calendar appear, allowing a date in, two
re-assignment dates, and a date out to be assigned (the language for the
calendar and populating those fields is the first six sets of code below, and
works fine). The seventh piece of code is supposed to calculate the number
of elapsed work days between the DateIn and DateOut when you click in that
field. This code calculates correctly; however, when I populate the
DaysElapsed field it simultaneously changes the DateIn field date to one day
after the DateOut field.
1. Can anyone please tell me what I need to do so the DateIn field does not
change when the calculation occurs?
2. Is there a better way (than clicking the DaysElapsed field) to populate
the DaysElapsed field with the calculated integer when I enter the date in
the DateOut field? (The perfect solution would be if the calculation would
run when I populate the DateOut field with a date and the DaysElapsed field
would be populated with the calculated integer.)
Thanks for any assistance. The visual basic language from the database
follows:
Option Compare Database
Dim cboOriginator As ComboBox
Private Sub Calendar4_Click()
cboOriginator.Value = Calendar4.Value
cboOriginator.SetFocus
Calendar4.Visible = False
Set cboOriginator = Nothing
End Sub
Private Sub Ctl1stReassignmentDate_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Set cboOriginator = Ctl1stReassignmentDate
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub Ctl2ndReassignmentDate_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
Set cboOriginator = Ctl2ndReassignmentDate
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub DateIn_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = DateIn
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub DateOut_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = DateOut
Calendar4.Visible = True
Calendar4.SetFocus
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub DaysElapsed_Click()
Dim intCount As Integer
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [Date] FROM tblHolidays", dbOpenSnapshot)
DateIn = DateIn + 1
intCount = 0
Do While DateIn <= DateOut
rst.FindFirst "[Date] = #" & DateIn & "#"
If Weekday(DateIn) <> vbSunday And Weekday(DateIn) <> vbSaturday Then
If rst.NoMatch Then intCount = intCount + 1
End If
DateIn = DateIn + 1
Loop
DaysElapsed = intCount
End Sub