Events - controls visible/hidden depending on a check box

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

Guest

I have the following code set up. The comments give a fairly good idea of
what I am trying to achieve. The problem is that, when I first go into the
form, more often than not, if the check box is ticked, the details label and
combo box don't display. I can only get them to display by unchecking and
rechecking. I think it's the OnActivate event that's causing the problem. Is
there anything I'm missing or have I used the wrong event?

' On opening the form, checks the status of chkFatigueMedication to
determine whether to
' display the details label and box.

Private Sub Form_OnActivate()
If Me.chkFatigueMedication = -1 Then
Me.lblBowelMedicationDetails.Visible = True
Me.memBowelMedication.Visible = True
End If

' After check box has been updated,
' if it has been checked, the details label and box will be displayed
' if it has been unchecked , the details label and box will be hidden and
the contents
' of the details box deleted.

Private Sub chkFatigueMedication_AfterUpdate()
If Me.chkFatigueMedication <> 0 Then
Me.lblFatigueMedicationDetails.Visible = True
Me.memFatigueMedication.Visible = True
Else
Me.lblFatigueMedicationDetails.Visible = False
Me.memFatigueMedication.Visible = False
Me.memFatigueMedication.Value = Null
End If
End Sub

Kind regards

Tony
 
Use the form's Current event. That way it will check the values for each
record and set the visibility appropriately. Be sure you add code to handle
new records correctly:

If Me.NewRecord Then
'Set visibility for new records
Else
'Set visibility for existing records
End If
 

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

Back
Top