Checkbox values compared to a date value

O

OzPete

Hi all,

Firstly, I am not sure of the date values (1-7)of the days of the week, but
I need to achieve this end result

So I am making some assumtions here to explain my challenge...
Sunday = 1, Monday = 2, etc
checkbox ticked has a value of -1
I have seven checkboxes in a table [SCRIPTS] and they are named [Sun] thru
to [Sat] to represent the days of the week. I need a form's (form name is
DISPENSE) On Current event to prompt me thus:

If the date value of Date() is 4 (Wednesday), and the record = -1 for field
[THU], I need a MsgBox to appear, saying "Take Aways to be supplied for
Tomorrow". As is now evident, I need a MsgBox to appear at Dispensation
time on Wednesday, to enable a takeaway prescription to be supplied for the
next day (Thursday), when the client cannot attend the pharmacy.

Can someone suggest the code to include in the On Current event to check the
date value (1-7) against the checkbox, and produce the MsgBox? (and is the
On Current event the best place to position the code?)

[slowly getting through these challenges.... :)]
tia

OzPete
 
W

William Taylor

check out the DatePart function in Access, and other functions associated
with date parsing. This will give you the tools and samples needed for
working with dates.
HTH
 
D

Douglas J. Steele

DatePart("d",Date()) is going to give you the day part of the date. In other
words, today being 15 Dec, 2003, it's going to give you 15.

You want Weekday(Date())
 
O

OzPete

Thanks William,

I now know that Sunday is 0, Monday is 1, etc..., but MSAccess Help didn't
give me enough examples to compare it to a checkbox too... what I am trying
to achieve is this...

Private Sub Form-Open
If Today is Monday Then
If Check44 is ticked Then
MsgBox "Takeaways Time Boys and Girls!"
End If
End If
End Sub

So I tried

Private Sub Form-Open
If DatePart("d",Date()) = 1 Then
If Check44 <> 0 Then
MsgBox "Takeaways Time Boys and Girls!"
End If
End If
End Sub

But nothing happens...

Any clues and/or corrections that my sad brain is lacking?

TIA
OzPete
 
D

Douglas J. Steele

The procedure associated with opening a form is

Private Sub Form_Open(Cancel As Integer)

so obviously you're not cutting-and-pasting your actual code into your
posts. That makes it kind of hard for anyone to offer suggestions as to why
it's not working.
 
O

OzPete

Tried that Doug,

didn't work...

got any more complete looking code that may fit the bill?

cheers
Pete
 
D

Douglas J. Steele

Okay, let's try debugging.

Private Sub Form_Open(Cancel As Integer)
On Error Resume Next
Me![Image40].Picture = Application.CurrentProject.Path & "\" &
[PhotoFile]
MsgBox "Today's " & Date() & ", and it's weekday " & Weekday(Date)
If Weekday(Date) = 1 Then
MsgBox "The value of Check44 is " & Check44
If Check44 <> 0 Then
MsgBox "Takeaways Time Boys and Girls!"
End If
End If
End Sub

What do you get?

--
Doug Steele, Microsoft Access MVP

(No private e-mails, please)



OzPete said:
Here's the code copied and pasted:

Private Sub Form_Open(Cancel As Integer)
On Error Resume Next
Me![Image40].Picture = Application.CurrentProject.Path & "\" &
[PhotoFile]
If Weekday(Date) = 1 Then
If Check44 <> 0 Then
MsgBox "Takeaways Time Boys and Girls!"
End If
End If
End Sub

thanks for your input Douglas...

OzPete

Douglas J. Steele said:
The procedure associated with opening a form is

Private Sub Form_Open(Cancel As Integer)

so obviously you're not cutting-and-pasting your actual code into your
posts. That makes it kind of hard for anyone to offer suggestions as to why
it's not working.
 
O

OzPete

Here's the code copied and pasted:

Private Sub Form_Open(Cancel As Integer)
On Error Resume Next
Me![Image40].Picture = Application.CurrentProject.Path & "\" &
[PhotoFile]
If Weekday(Date) = 1 Then
If Check44 <> 0 Then
MsgBox "Takeaways Time Boys and Girls!"
End If
End If
End Sub

thanks for your input Douglas...

OzPete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top