Check box visible on certain days

todgers

Registered User.
Local time
Today, 13:02
Joined
Mar 28, 2006
Messages
42
Hiya

I'm trying to get a check box to be visible/enabled on Tuesdays, Thursdays and Sundays.
I've been dabbling with the code and 'DatePart' but with little effect. I've been trying other suggestions on other threads but am still struggling I'm afraid.
All help much appreciated, and I'm fairly new to access and have a large work objective to cope with, see below for my poor effort so far

Private Sub Datapulse_Enter()

If Datapulse = DatePart("1", "3", "5") Then
Datapulse.Visible = False
Else
Datapulse.Visible = True
End If

End Sub​
 
todgers,

If Datapulse is the CheckBox, I don't think that you want to
use one of its events.

If you want the form to display the CheckBox on only those days,
use the Form's OnCurrent event and put the following:

Code:
Select Case DatePart("w", Date)
    Case "1", "3", "5"
       Me.DataPulse.Visible = True
    Case Else
       Me.DataPulse.Visible = False
    End Select

Wayne
 
Thanks Wayne

I have done as instructed although its still visible all the time

Sorry if its stupid but whats the 'me' bit in the code
 
todgers said:
Thanks Wayne

I have done as instructed although its still visible all the time

Sorry if its stupid but whats the 'me' bit in the code

Me references the form you are on.

Me.Datepulse --- says to look at Datepulse on the current form.
 
Thanks Selena

Just a thought, does it matter how my date is formatted on the form.

Has it got to be so it shows the days of the week?
 
todgers said:
Thanks Selena

Just a thought, does it matter how my date is formatted on the form.

Has it got to be so it shows the days of the week?

I don't think so, I do belive Access can tell with the day of the week being posted on the form.

have you tried using a message box to see what the day of the week is showing?

try
msgbox('fieldname of the date field')

also, not to sound stupid, but the name of the checkbox is datepulse? What is the name of the field holding the date you are checking.

CAn you please post a screen print of that form in design view. so I can see the controls and the name of the controls.
 
Hope this helps, be nice to be sorted out!

dbscreen6jx.jpg
 
Last edited:
todgers said:
Hope this helps, be nice to be sorted out!

dbscreen6jx.jpg

Hey baby..it's to small..and when i saved it and enlarged it...it was blurry..can you make it a bit bigger....
 
Code:
Select Case DatePart("w", Date)
    Case "1", "3", "5"
       Me.DataPulse.Visible = True
    Case Else
       Me.DataPulse.Visible = False
    End Select

In a select case the field name should be after the Select Case statment, however since you are using the date part function the name of the field would be 'date'. What is the name of the field the date is stored in. That is the name you need to put there;
Code:
DatePart("w", [B]Date[/B])

Once you correctly assign the field name where 'date' is it should work.
 
Sorry if I'm being thick but I thought it was a case of the below

Select Case DatePart("w", Tape.Date)

I now get 'Variable not defined' and it highlights the 'Tape' bit.
 
todgers said:
Sorry if I'm being thick but I thought it was a case of the below



I now get 'Variable not defined' and it highlights the 'Tape' bit.

I don't think you need to put .Date at the end.

Try just Tape

Code:
Select Case DatePart("w", Tape)

If that does't work, try Me.Tape.Value or Me.Tape.Text. I'm taking a VB.net class too..so i sometimes get them mixed with each other. :(
 
OK so the code I now have is as below (date now works, welcome to the world of strange)
Not sure why but the below code shows the checkbox on the first record, then it goes when you go to the next record never to return on any records after that.

Private Sub Form_Current()

Select Case DatePart("w", Date)
Case "1", "3", "5"
Me.Datapulse.Visible = True
Case Else
Me.Datapulse.Visible = False
End Select

End Sub
 
OK so the code I now have is as below (date now works, welcome to the world of strange)
Not sure why but the below code shows the checkbox on the first record, then it goes when you go to the next record never to return on any records after that.

Private Sub Form_Current()

Select Case DatePart("w", Date)
Case "1", "3", "5"
Me.Datapulse.Visible = True
Case Else
Me.Datapulse.Visible = False
End Select

End Sub

I'll owe you pint after this
 
todgers said:
OK so the code I now have is as below (date now works, welcome to the world of strange)
Not sure why but the below code shows the checkbox on the first record, then it goes when you go to the next record never to return on any records after that.



I'll owe you pint after this

I suggest you add this code to the above sub procedure.

Code:
msgbox(DatePart("w", Date))
It should fire evertime you move records. That way you can see what is being read. That will in turn help you to determin why it isn't changing on new records.

Let me know how that works.

I leave today at 2:30 Eastern, but will return tomorrow at 8:00 Eastern.
 
todgers said:
It returns a number 4

That's why it isn't returning vis. That record. Is 4 the correct day of the week for that record?
 
Well the record displayed is the 12th January which is a Thursday.

I am correct in thinking that Sunday = 1, Monday = 2 and so on
 

Users who are viewing this thread

Back
Top Bottom