Problems with Dates on a Form

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Hello there,

I've got a form with a date text box on it. When the
date is a Saturday I'd like a checkbox ticked
(called 'SatCheck') and the same if the date is a
Wednesday (WedCheck). I've got the following code on the
AfterUpdate event of the Date text box but it doesn't
work.......what am I doing wrong here!!? This should be
so simple but I'm stuck!

Private Sub txtDate_AfterUpdate()

Dim TodaysDate, DayOfWeek

TodaysDate = txtDate
DayOfWeek = WeekDay(TodaysDate)

If DayOfWeek = 7 Then
SatCheck = True
ElseIf DayOfWeek = 4 Then
WedCheck = True
Else
SatCheck = False
WedCheck = False
End If

End Sub

Hope you can help me with this!

Thanks in advance,

Lew
 
You may be in the UK? If so, Access may not be recognising you dd/mm/yyyy
format as a date.
Set the Format property of your unbound text box to:
Short Date
and be explicit about the date type of your variables.

Private Sub txtDate_AfterUpdate()
Dim TodaysDate As Date
Dim DayOfWeek As Integer

TodaysDate = Nz(Me.txtDate, Date())
DayOfWeek = WeekDay(TodaysDate)

Me.SatCheck.Value = (DayOfWeek = vbSaturday)
Me.WecCheck.Value = (DayOfWeek = vbWednesday)
End Sub

For more information on how to avoid the 3 conditions where Access can
misunderstand your date format, see:
International Dates in Access
at:
http://allenbrowne.com/ser-36.html
 
Try

Private sub UpdateChecks()
Me!SatCheck = False
Me!WedCheck = False
Select Case Weekday(Me!txtDate)
case vbSaturday
Me!SatCheck = True
case vbWednesday
Me!WedCheck = True
end select
End sub

Call this sub in the Form_Current and txtDate_AfterUpdate
events.

hth

Chris
 
Hi Allen,
Thanks very much to you (and to Chris) for your
suggestions and input but neither would work...for the
life of me I can't think why as my system dates are OK
etc...
Anyway, I've just put the following Immediate If
statements as the Control Source for each checkbox
(without any code in the background) and all is now
working fine:

SatCheck =IIf(Weekday([txtDate1])=7,-1,0)
WedCheck =IIf(Weekday([txtDate1])=4,-1,0)

Best wishes for the Christmas season,

Lee
(PS: Yes I am from the UK - you can tell by my posh
accent) ;-)
 
Lee,

On this post your date field is called "txtDate1", on your last post there
was no 1, just "txtDate". Could that have been the problem?

Kelvin

Lee said:
Hi Allen,
Thanks very much to you (and to Chris) for your
suggestions and input but neither would work...for the
life of me I can't think why as my system dates are OK
etc...
Anyway, I've just put the following Immediate If
statements as the Control Source for each checkbox
(without any code in the background) and all is now
working fine:

SatCheck =IIf(Weekday([txtDate1])=7,-1,0)
WedCheck =IIf(Weekday([txtDate1])=4,-1,0)

Best wishes for the Christmas season,

Lee
(PS: Yes I am from the UK - you can tell by my posh
accent) ;-)
-----Original Message-----
You may be in the UK? If so, Access may not be recognising you dd/mm/yyyy
format as a date.
Set the Format property of your unbound text box to:
Short Date
and be explicit about the date type of your variables.

Private Sub txtDate_AfterUpdate()
Dim TodaysDate As Date
Dim DayOfWeek As Integer

TodaysDate = Nz(Me.txtDate, Date())
DayOfWeek = WeekDay(TodaysDate)

Me.SatCheck.Value = (DayOfWeek = vbSaturday)
Me.WecCheck.Value = (DayOfWeek = vbWednesday)
End Sub

For more information on how to avoid the 3 conditions where Access can
misunderstand your date format, see:
International Dates in Access
at:
http://allenbrowne.com/ser-36.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 
'fraid not, just a typo!

Thanks for the thought though.

Lee
-----Original Message-----
Lee,

On this post your date field is called "txtDate1", on your last post there
was no 1, just "txtDate". Could that have been the problem?

Kelvin

Lee said:
Hi Allen,
Thanks very much to you (and to Chris) for your
suggestions and input but neither would work...for the
life of me I can't think why as my system dates are OK
etc...
Anyway, I've just put the following Immediate If
statements as the Control Source for each checkbox
(without any code in the background) and all is now
working fine:

SatCheck =IIf(Weekday([txtDate1])=7,-1,0)
WedCheck =IIf(Weekday([txtDate1])=4,-1,0)

Best wishes for the Christmas season,

Lee
(PS: Yes I am from the UK - you can tell by my posh
accent) ;-)
-----Original Message-----
You may be in the UK? If so, Access may not be recognising you dd/mm/yyyy
format as a date.
Set the Format property of your unbound text box to:
Short Date
and be explicit about the date type of your variables.

Private Sub txtDate_AfterUpdate()
Dim TodaysDate As Date
Dim DayOfWeek As Integer

TodaysDate = Nz(Me.txtDate, Date())
DayOfWeek = WeekDay(TodaysDate)

Me.SatCheck.Value = (DayOfWeek = vbSaturday)
Me.WecCheck.Value = (DayOfWeek = vbWednesday)
End Sub

For more information on how to avoid the 3 conditions where Access can
misunderstand your date format, see:
International Dates in Access
at:
http://allenbrowne.com/ser-36.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


I've got a form with a date text box on it. When the
date is a Saturday I'd like a checkbox ticked
(called 'SatCheck') and the same if the date is a
Wednesday (WedCheck). I've got the following code
on
the
AfterUpdate event of the Date text box but it doesn't
work.......what am I doing wrong here!!? This
should
be
so simple but I'm stuck!

Private Sub txtDate_AfterUpdate()

Dim TodaysDate, DayOfWeek

TodaysDate = txtDate
DayOfWeek = WeekDay(TodaysDate)

If DayOfWeek = 7 Then
SatCheck = True
ElseIf DayOfWeek = 4 Then
WedCheck = True
Else
SatCheck = False
WedCheck = False
End If

End Sub

Hope you can help me with this!

Thanks in advance,

Lew


.


.
 
The other thing could be that you didn't specify the data types for
TodaysDate. When you set TodaysDate = txtDate it could have been setting
the data type to an integer. Then WeekDay([TodaysDate]) will yield the
wrong result since TodaysDate isn't a Date type. I tried it and it seems to
work fine.

Kelvin

Lee said:
'fraid not, just a typo!

Thanks for the thought though.

Lee
-----Original Message-----
Lee,

On this post your date field is called "txtDate1", on your last post there
was no 1, just "txtDate". Could that have been the problem?

Kelvin

Lee said:
Hi Allen,
Thanks very much to you (and to Chris) for your
suggestions and input but neither would work...for the
life of me I can't think why as my system dates are OK
etc...
Anyway, I've just put the following Immediate If
statements as the Control Source for each checkbox
(without any code in the background) and all is now
working fine:

SatCheck =IIf(Weekday([txtDate1])=7,-1,0)
WedCheck =IIf(Weekday([txtDate1])=4,-1,0)

Best wishes for the Christmas season,

Lee
(PS: Yes I am from the UK - you can tell by my posh
accent) ;-)

-----Original Message-----
You may be in the UK? If so, Access may not be
recognising you dd/mm/yyyy
format as a date.
Set the Format property of your unbound text box to:
Short Date
and be explicit about the date type of your variables.

Private Sub txtDate_AfterUpdate()
Dim TodaysDate As Date
Dim DayOfWeek As Integer

TodaysDate = Nz(Me.txtDate, Date())
DayOfWeek = WeekDay(TodaysDate)

Me.SatCheck.Value = (DayOfWeek = vbSaturday)
Me.WecCheck.Value = (DayOfWeek = vbWednesday)
End Sub

For more information on how to avoid the 3 conditions
where Access can
misunderstand your date format, see:
International Dates in Access
at:
http://allenbrowne.com/ser-36.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


I've got a form with a date text box on it. When the
date is a Saturday I'd like a checkbox ticked
(called 'SatCheck') and the same if the date is a
Wednesday (WedCheck). I've got the following code on
the
AfterUpdate event of the Date text box but it doesn't
work.......what am I doing wrong here!!? This should
be
so simple but I'm stuck!

Private Sub txtDate_AfterUpdate()

Dim TodaysDate, DayOfWeek

TodaysDate = txtDate
DayOfWeek = WeekDay(TodaysDate)

If DayOfWeek = 7 Then
SatCheck = True
ElseIf DayOfWeek = 4 Then
WedCheck = True
Else
SatCheck = False
WedCheck = False
End If

End Sub

Hope you can help me with this!

Thanks in advance,

Lew


.


.
 
Back
Top