Problem with Enabled and Visible properties in a form

  • Thread starter Thread starter Amit
  • Start date Start date
A

Amit

Hi,

I have a form which has many controls, two of which are a
combo box and a textbox. The textbox is visible and
enabled only if a certain value ("Inactive") is selected
in the combo box. I have the following code (thanks to one
of the MVPs here) in the 'Enter' and 'AfterUpdate' events
of the combo box:

Me.StaffStatusChangeDate.Visible = (Me.StaffStatus
= "Inactive")
Me.StaffStatusChangeDate.Enabled = (Me.StaffStatus
= "Inactive")

Also, in the GetFocus event of the textbox, I set focus to
the combo box if the value is "Active".

This is working fine except for one glitch. When I move
from one record to the next in the form using the
navigation keys, and if the cursor happens to be in a
control other than the combo box or the textbox, the
textbox is displayed even if the combo box is "Active".

I think I need to place the same code in some other
control in the form, so that the textbox is displayed/not
displayed irrespective of the control where the cursor is
when I navigate. Any pointers??

Thanks!

-Amit
 
The OnCurrent event of the form runs when you move from one record to the
next or when you go to the first record as you open the form.
 
Wayne,

Thanks for your help!

-Amit
-----Original Message-----
The OnCurrent event of the form runs when you move from one record to the
next or when you go to the first record as you open the form.

--
Wayne Morgan





.
 
Wayne,

That totally worked, but I have another problem. The
default value for the textbox (date) is not working. I
have the following code in the form:

Private Sub cboIndStatus_AfterUpdate()
'Change the IndStatusChangeDate to Visible and Enabled if
IndStatus is Inactive
Me.IndStatusChangeDate.Visible = (Me.IndStatus
= "Inactive")
Me.IndStatusChangeDate.Enabled = (Me.IndStatus
= "Inactive")
If (Me.IndStatus = "Inactive") Then
Me.IndStatusChangeDate.SetFocus
Me.IndStatusChangeDate.DefaultValue = Date
End If
End Sub

For some reason, the default value is not being filled in
for IndStatusChangeDate textfield. When I go to the form
and select "Inactive" in the combo box, I'm taken to the
textbox, but it remains blank and is not filled in with
the default date (today's date). Not sure why....

TIA.

-Amit
 
It has to do with the way the Default Value works. The Default Value is used
when you move to a new record to pre-populate the field or control. Once you
are there, setting the Default Value won't do anything until you once again
move to a new record. If the Default Value is always going to be the current
date, you could just hard code it into the control's Properties sheet in
design view. The other option would be to set the Value of the control in
your code instead of the Default Value.

In the Properties sheet, setting the Default Value to the current date would
look like

=Date()

Place this in the Default Value line of the Data tab of the control's
Properties sheet with the form open in design view.
 
Back
Top