Hey Allen,
Thanks - I corrected this: Call Status_Price_Reduced_AfterUpdate
in the sub_form_Current()
...BUT...basically the form is not working.
1. I am not using single form - not continous
2. I am not sure what you mean by bound, but the form is built on an
underlying table which does have foreign keys established in some of the
other fields.
Current problem:
The unchecked records (status_current_price=ON) are still showing the items
which should be INVISIBLE including:
Current_Price
Price_Reduction_frame.Visible
Price_Reduction_Date.Visible
Additionally:
If I attempt to create a new record, the immediately present unchecked box
is not hiding or making invisible the:
Current_Price
Price_Reduction_frame.Visible
Price_Reduction_Date.Visible
...I am really confused - I find it really difficult to work out the problem
inside VBA. Here is my full revised code:
Private Sub Form_Current()
Call Status_Price_Reduced_AfterUpdate
End Sub
Private Sub Status_Price_Reduced_Click()
Status_Price_Reduced.SetFocus
If Status_Price_Reduced = -1 Then
Current_Price.Visible = True
Price_Reduction_frame.Visible = True
Price_Reduction_Date.Visible = True
Else
Current_Price.Visible = False
Price_Reduction_frame.Visible = False
Price_Reduction_Date.Visible = False
End If
End Sub
Private Sub Status_Price_Reduced_AfterUpdate()
On Error GoTo Err_Handler
Dim bShow As Boolean
bShow = Me.Status_Price_Reduced.Value
MsgBox (bShow)
If Me.Current_Price.Visible <> bShow Then
Current_Price.Visible = bShow
Price_Reduction_frame.Visible = bShow
Price_Reduction_Date.Visible = bShow
End If
Exit_Handler:
Exit Sub
Err_Handler:
Select Case Err.Number
Case 2164, 2165 'Can't disable/hide the control with focus.
Me.[SomeOtherControlThatIsAlwaysVisible].SetFocus
Resume
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
End Select
End Sub
Allen Browne said:
The Current event fires whenever to form loads a record. It's the one to
manipulate changes you want to see when a record loads.
This assumes:
- this is single form view (not Continuous or Datasheet);
- it's a bound form;
- Current_Price is bound to a field (not an expression starting with =).
I've picked up the names of the controls from your code, so you should not
have to change any of the names except this one:
SomeOtherControlThatIsAlwaysVisible
The error handling is needed because it causes an error if a control has
focus at the time you try to hide it. That could happen in the Current event
of the form.
Dirk is right. I should have called the AfterUpdate since that's the
event
I
used:
Private Sub Form_Current()
Call Status_Price_Reduced_AfterUpdate
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to the newsgroup. (Email address has spurious "_SpamTrap")
Hold - now it has stopped working again - this I don't understand - the
unchecked boxes are ignoring the turn-off-visibility rules for the other
conditioned form elements....very frustrating!
- Jason
Use the Current event of the form.
The code below uses the AfterUpdate event procedure of the check
box
to
respond to the change. The same code is called by the form's Current
event.
Since the code can be triggered by changing record, you need to avoid
hiding
the control that has the focus. It's also more efficient to change the
visibility of the controls only if needed.
Private Sub Form_Current()
Call Status_Price_Reduced_Click
End Sub
Private Sub Status_Price_Reduced_AfterUpdate()
On Error Goto Err_Handler
Dim bShow As Boolean
bShow = Me.Status_Price_Reduced.Value
If Me.Current_Price.Visible <> bShow Then
Current_Price.Visible = bShow
Price_Reduction_frame.Visible = bShow
Price_Reduction_Date.Visible = bShow
End If
Exit_Handler:
Exit Sub
Err_Handler:
Select Case Err.Number
Case 2164, 2165 'Can't disable/hide the control with focus.
Me.[SomeOtherControlThatIsAlwaysVisible].SetFocus
Resume
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description
Resume Exit_Handler
End Select
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to the newsgroup. (Email address has spurious "_SpamTrap")
Hi Guys...I really need some help here. I am frustrated by the
results
of
some basic vba
code to create a condition based on a the status of a CHECK box
in
my
form.
I wish to control the immediate VISIBILITY of other elements on the
form
based
on whether the CHECKBOX is ticked.
I placed the code inside the CHECKBOX sub.
HOWEVER, it does not work when the FORM loads.
It only works if you first click inside the checkbox and then out
again
to
force the condition.
I really don't see why this. Surely when the form loads the condition
of
the CHECKBOX is
determined.
I know you will come back to me and say place this code in Form Onload
event. But, I have
tried this in the past and also achieved inconsistent results.
Can
you
help
me understand how
to create a universal application of my condition everytime a user
opens
up
the form or even
scrolls to a next record. I think it must be something very simple...I
really appreciate your help
See below:
Private Sub Status_Price_Reduced_Click()
Status_Price_Reduced.SetFocus
If Status_Price_Reduced = -1 Then
Current_Price.Visible = True
Price_Reduction_frame.Visible = True
Price_Reduction_Date.Visible = True
Else
Current_Price.Visible = False
Price_Reduction_frame.Visible = False
Price_Reduction_Date.Visible = False
End If
End Sub