Tick Box problem

agehoops

Registered User.
Local time
Today, 00:14
Joined
Feb 11, 2006
Messages
351
Hi.
I've set a up a tick box to choose the option to have an extension on a booking. If it is ticked, then i want it to add an extra £5 to the final cost, BUT, it can ONLY be ticked, if the Day of week is a Friday or a Saturday, AND if the time period is an evening.

Is there a way of making it, so that if the day of week is equal to friday or saturday, AND time period is equal to evening, the tick box becomes active, or visable, and if it is any other time period and day of week, it cannot?

Thanks
 
Easy answer is yes you can. The difficult part is determining the criteria of day/time in your code. You will need an if statement on the forms On Open event. You would define variables that you would assign the current day/time to and then if they meet your criteria you would assign either enabled=true or visible=true to your checkbox (or both). Leave the default for both options as false so that it usually will not appear to the end user, and will be there only when the option is allowed.

I am not the best at coding dates and such, but if you search the forums you should find the exact code you need to get the day from the system, and the time should be simple enough.

Another option would be to place the code on the checkbox itself. In the On Click event, you could place code to check the day/time and if it is met you allow the check to happen, else display a message box stating that it can only be used on xx days, after xx time. Finish the else statement up with a checkbox = 0 and the checkbox would be cleared.

The forms forum and the VBA forum will most likely hold the answers you are looking for.
 
Ok. I've just put the following code on the After_Update event for the Time Period box. Is this right, or completely wrong:

Private Sub Time_Period_AfterUpdate()
If Time_Period = Evening And Day_Of_Week = Friday Or Saturday Then
Extension.Visible = True & Extension.Locked = False & Extension.Enabled = True

End If
If Time_Period <> Evening And Day_Of_Week <> Friday Or Saturday Then
Extension.Visible = False & Extension.Locked = True & Extension.Enabled = False

End If
End Sub


Thanks
 
If Time_Period = Evening And Day_Of_Week = Friday Or Saturday Then
Extension.Visible = True & Extension.Locked = False & Extension.Enabled = True


Create variables
Dim Whattime as date
Dim Whichday as string

Whichday = format([Yourdatetimefield],"dddd"
(Whichday now contains the day)

Whattime = format([yourdatetimefield],"Long Time")
(Whattime now contains the time (HH:MM:SS))

You can now check these fields to see if they meet the required criteria
 
Sorry I didnt get back sooner, but Smart has it right. If you are going to run the code to get the proper date, assign it to a varible and then run the comparisons against the varible.

Like Smart posted

Dim Whattime as date
Dim Whichday as string

Whichday = format([Yourdatetimefield],"dddd"
(Whichday now contains the day)

Whattime = format([yourdatetimefield],"Long Time")
(Whattime now contains the time (HH:MM:SS))


Then you could use in the after update event code to check the varible against the allowed days & times.

If the criteria is met do nothing *** You if statements comparing the varibles against the allowed dates & times ***
Else me.checkbox_1 = False *** THIS UNCHECKS THE TIC BOX where me.checkbox_1 is the name of the TIC box*****
mesgbox "This feature is only availible on XX days @ xx times." ***Presents the User with a message ***
 

Users who are viewing this thread

Back
Top Bottom