Conditionally disabling controls on subform

G

Guest

I would like to set Enabled=False for a group of 4 combo box controls on a subform (datasheet view) if the following criteria are true (currently selected day of week is Monday - I'm using WeekDayName(weekDay([fldDate])) and if the booking time is between 7:00 AM and 10:00 AM ([fldTeeTime]). On Mondays within that time range I would like to disable the combo controls so bookings cannot be made. After 10:00 AM the combo boxes should remain enabled

Thanks in advance
 
M

MacDermott

AFAIK conditional formatting is only available for textboxes.

HTH
- Turtle

Bob Mullen said:
I would like to set Enabled=False for a group of 4 combo box controls on a
subform (datasheet view) if the following criteria are true (currently
selected day of week is Monday - I'm using WeekDayName(weekDay([fldDate]))
and if the booking time is between 7:00 AM and 10:00 AM ([fldTeeTime]). On
Mondays within that time range I would like to disable the combo controls so
bookings cannot be made. After 10:00 AM the combo boxes should remain
enabled.
 
G

Guest

1) Add the code below to your for
2) Change the control names to the ones you us
3) Set the Timer Interval to 1000 (=1 second) (Form properties/Event

'-----Start Code-----------------
Private Sub Form_Timer(
' uncomment the following line if you want to use the day Nam
'If UCase(WeekdayName(Weekday(Date))) = "MONDAY" The
'comment the following line if using day Nam
If Weekday(Date) = 2 Then ' 2 = Monda
' hours between 7AM and 10A
If Hour(Now()) >= 7 And Hour(Now()) <= 10 The
'can't disable if control has focus so move it t
'another control, button, etc or close the for
Me.Text8.SetFocu
Me.Text0.Enabled = Fals
Me.Text2.Enabled = Fals
Me.Text4.Enabled = Fals
Me.Text6.Enabled = Fals
Els
Me.Text0.Enabled = Tru
Me.Text2.Enabled = Tru
Me.Text4.Enabled = Tru
Me.Text6.Enabled = Tru
End I
End I
End Su

'-----End Code-------------------

Note: the timer runs the code every second that the form is open. If that slows Access down too much for you, change the timer interval to 5000 (5 seconds)..... the timer interval number is calculated by

timer interval number = Number of seconds X 1000

HT

Steve
 
M

MacDermott

This approach will enable/disable all four controls on each record displayed
in your subform.
If that's what you want, great!

If you're looking to show different controls disabled on different records
in your subform, you might be stuck with textboxes - and a different coding
approach.

HTH
- Turtle
SteveS said:
1) Add the code below to your form
2) Change the control names to the ones you use
3) Set the Timer Interval to 1000 (=1 second) (Form properties/Event)

'-----Start Code------------------
Private Sub Form_Timer()
' uncomment the following line if you want to use the day Name
'If UCase(WeekdayName(Weekday(Date))) = "MONDAY" Then
'comment the following line if using day Name
If Weekday(Date) = 2 Then ' 2 = Monday
' hours between 7AM and 10AM
If Hour(Now()) >= 7 And Hour(Now()) <= 10 Then
'can't disable if control has focus so move it to
'another control, button, etc or close the form
Me.Text8.SetFocus
Me.Text0.Enabled = False
Me.Text2.Enabled = False
Me.Text4.Enabled = False
Me.Text6.Enabled = False
Else
Me.Text0.Enabled = True
Me.Text2.Enabled = True
Me.Text4.Enabled = True
Me.Text6.Enabled = True
End If
End If
End Sub

'-----End Code--------------------

Note: the timer runs the code every second that the form is open. If that
slows Access down too much for you, change the timer interval to 5000 (5
seconds)..... the timer interval number is calculated by:
 

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