Disabling Form Options depending on bound control values (Access 9

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with the following onopen event where [Stock_Availability] and
[Service_Availability] is a bound yes/no tick option - but I get erratic
results depending on which record is shown from the underlying table/query -
how can I get the code to react only to the record that is displayed? I get
erratic results on a new record aswell - should I be putting the code
somewhere else?
The code does work for the afterupdate event on the bound controls. Please
help, thanks,
Richard

Private Sub Form_Open(Cancel As Integer)
If Me.Stock_Availability = True Then
Me.Qty_Available.Enabled = True
Me.Unit_Price.Enabled = True
Me.Condition_Code.Enabled = True
Me.Stock_Notes.Enabled = True
Else: Me.Qty_Available.Enabled = False
Me.Unit_Price.Enabled = False
Me.Condition_Code.Enabled = False
Me.Stock_Notes.Enabled = False
End If

If Me.Service_Availablility = True Then
Me.Avg_Bench_Check.Enabled = True
Me.Avg_Repair_Cost.Enabled = True
Me.Avg_Overhaul_Cost.Enabled = True
Me.TAT.Enabled = True
Me.Service_Notes.Enabled = True
Else: Me.Avg_Bench_Check.Enabled = False
Me.Avg_Repair_Cost.Enabled = False
Me.Avg_Overhaul_Cost.Enabled = False
Me.TAT.Enabled = False
Me.Service_Notes.Enabled = False
End If
End Sub
 
Use the Current event of the form so that the properties are set for each
record.

This kind of thing:

Private Sub Form_Current()
Dim bEnabled As Boolean

bEnabled = Nz(Me.Stock_Availability.Value, False)
Me.Qty_Available.Enabled = bEnabled
Me.Unit_Price.Enabled = bEnabled
Me.Condition_Code.Enabled = bEnabled
Me.Stock_Notes.Enabled = bEnabled

bEnabled = Nz(Me.Service_Availablility.Value, False)
Me.Avg_Bench_Check.Enabled = bEnabled
Me.Avg_Repair_Cost.Enabled = bEnabled
Me.Avg_Overhaul_Cost.Enabled = bEnabled
Me.TAT.Enabled = bEnabled
Me.Service_Notes.Enabled = bEnabled
End Sub

Don't forget to add error handling to SetFocus to a control that will not be
disabled.

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

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

message
news:[email protected]...
 
Thanks Allen, I tried the original code on the forms On Current event and got
the desired result also.

Allen Browne said:
Use the Current event of the form so that the properties are set for each
record.

This kind of thing:

Private Sub Form_Current()
Dim bEnabled As Boolean

bEnabled = Nz(Me.Stock_Availability.Value, False)
Me.Qty_Available.Enabled = bEnabled
Me.Unit_Price.Enabled = bEnabled
Me.Condition_Code.Enabled = bEnabled
Me.Stock_Notes.Enabled = bEnabled

bEnabled = Nz(Me.Service_Availablility.Value, False)
Me.Avg_Bench_Check.Enabled = bEnabled
Me.Avg_Repair_Cost.Enabled = bEnabled
Me.Avg_Overhaul_Cost.Enabled = bEnabled
Me.TAT.Enabled = bEnabled
Me.Service_Notes.Enabled = bEnabled
End Sub

Don't forget to add error handling to SetFocus to a control that will not be
disabled.

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

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

message
I have a form with the following onopen event where [Stock_Availability]
and
[Service_Availability] is a bound yes/no tick option - but I get erratic
results depending on which record is shown from the underlying
table/query -
how can I get the code to react only to the record that is displayed? I
get
erratic results on a new record aswell - should I be putting the code
somewhere else?
The code does work for the afterupdate event on the bound controls.
Please
help, thanks,
Richard

Private Sub Form_Open(Cancel As Integer)
If Me.Stock_Availability = True Then
Me.Qty_Available.Enabled = True
Me.Unit_Price.Enabled = True
Me.Condition_Code.Enabled = True
Me.Stock_Notes.Enabled = True
Else: Me.Qty_Available.Enabled = False
Me.Unit_Price.Enabled = False
Me.Condition_Code.Enabled = False
Me.Stock_Notes.Enabled = False
End If

If Me.Service_Availablility = True Then
Me.Avg_Bench_Check.Enabled = True
Me.Avg_Repair_Cost.Enabled = True
Me.Avg_Overhaul_Cost.Enabled = True
Me.TAT.Enabled = True
Me.Service_Notes.Enabled = True
Else: Me.Avg_Bench_Check.Enabled = False
Me.Avg_Repair_Cost.Enabled = False
Me.Avg_Overhaul_Cost.Enabled = False
Me.TAT.Enabled = False
Me.Service_Notes.Enabled = False
End If
End Sub
 
Back
Top