G
Guest
I have the following code in a form. I have two questions:
1) The bulk of the code is to populate an unbound field with the day of the
week. This piece of code works just find as long as the values are entered
from the keyboard. When the Default Value is set (to the current date), this
code does not produce any results--the day of week field is blank. If I type
over the default with any date, the code works again.
2) The last line is intended to reset the Default Value to the last entered
value to simplify data entry. I have used similar code in other applications
with no problems, but it is not working here. In this case, the default
appears as 12/30/1899 on the next record.
I have the same problem with a similar line of code for another field on the
same form. In that case, the next record does not show the default at all.
Can someone help in explaining why these problems are occurring and suggest
changes?
Thanks.
Private Sub SessionDate_AfterUpdate()
DOWHold = Weekday(Me.SessionDate.Value)
Select Case DOWHold
Case 1
Me.DayOfWeek = "Sunday"
Case 2
Me.DayOfWeek = "Monday"
Case 3
Me.DayOfWeek = "Tuesday"
Case 4
Me.DayOfWeek = "Wednesday"
Case 5
Me.DayOfWeek = "Thursday"
Case 6
Me.DayOfWeek = "Friday"
Case 7
Me.DayOfWeek = "Saturday"
End Select
Me.SessionDate.DefaultValue = Me.SessionDate
End Sub
1) The bulk of the code is to populate an unbound field with the day of the
week. This piece of code works just find as long as the values are entered
from the keyboard. When the Default Value is set (to the current date), this
code does not produce any results--the day of week field is blank. If I type
over the default with any date, the code works again.
2) The last line is intended to reset the Default Value to the last entered
value to simplify data entry. I have used similar code in other applications
with no problems, but it is not working here. In this case, the default
appears as 12/30/1899 on the next record.
I have the same problem with a similar line of code for another field on the
same form. In that case, the next record does not show the default at all.
Can someone help in explaining why these problems are occurring and suggest
changes?
Thanks.
Private Sub SessionDate_AfterUpdate()
DOWHold = Weekday(Me.SessionDate.Value)
Select Case DOWHold
Case 1
Me.DayOfWeek = "Sunday"
Case 2
Me.DayOfWeek = "Monday"
Case 3
Me.DayOfWeek = "Tuesday"
Case 4
Me.DayOfWeek = "Wednesday"
Case 5
Me.DayOfWeek = "Thursday"
Case 6
Me.DayOfWeek = "Friday"
Case 7
Me.DayOfWeek = "Saturday"
End Select
Me.SessionDate.DefaultValue = Me.SessionDate
End Sub