Split form and Enable/Disable

vapid2323

Scion
Local time
Today, 11:43
Joined
Jul 22, 2008
Messages
217
Ok I dont have a clue whats going on with this, my code is below and the issue is that when I change records my enable/disable options start getting mixed up for some reason!

After a while the fields might grey out even when they should be enabled, also sometimes the spit form will be grey but I can still edit in the top section. I thought it might be a Form.Repaint issue but thats not resolved the issues.

I have no idea whats up, is a split form normally like this with enable/disable? Or is my code not correct?

Code:
Private Sub Form_Current()
Dim tfValue As Boolean
 
If Me.Qual_Complete.Value = -1 Then
    tfValue = False
    With Me
    .Qual_ConfCall.Enabled = tfValue
    .Qual_ConfLetterSent.Enabled = tfValue
    .Qual_QAPPSenttoSite.Enabled = tfValue
    .Qual_ReminderEmail.Enabled = tfValue
    .Qual_QtoQCalls.Enabled = tfValue
    .Qual_InspectionDate.Enabled = tfValue
    .Qual_CompleteDate.Enabled = tfValue
    .Qual_ResponseReceived.Enabled = tfValue
    .Qual_ClosureLetter.Enabled = tfValue
    End With
Else
    tfValue = True
    With Me
    .Qual_ConfCall.Enabled = tfValue
    .Qual_ConfLetterSent.Enabled = tfValue
    .Qual_QAPPSenttoSite.Enabled = tfValue
    .Qual_ReminderEmail.Enabled = tfValue
    .Qual_QtoQCalls.Enabled = tfValue
    .Qual_InspectionDate.Enabled = tfValue
    .Qual_CompleteDate.Enabled = tfValue
    .Qual_ResponseReceived.Enabled = tfValue
    .Qual_ClosureLetter.Enabled = tfValue
    End With
End If
    tfValue = False
    Form.Repaint
End Sub
 
The issue with your code is with the line Form.Repaint - should be Me.Repaint but I don't believe that this line is necessary

I would suggest rewriting your code as follows:

Private Sub Form_Current()
Dim tfValue As Boolean

If Me.Qual_Complete.Value = -1 Then
tfValue = False
Else
tfValue = true
Endif

With Me
.Qual_ConfCall.Enabled = tfValue
.Qual_ConfLetterSent.Enabled = tfValue
.Qual_QAPPSenttoSite.Enabled = tfValue
.Qual_ReminderEmail.Enabled = tfValue
.Qual_QtoQCalls.Enabled = tfValue
.Qual_InspectionDate.Enabled = tfValue
.Qual_CompleteDate.Enabled = tfValue
.Qual_ResponseReceived.Enabled = tfValue
.Qual_ClosureLetter.Enabled = tfValue
End With

End Sub
 
Split forms allow beginners to easily make a form that would otherwise require a subform. However they have many limitations and misbehaviours when controlled by VBA.

My advice to all developers is don't bother ever using them. Use subforms.

BTW If Me.Qual_Complete is a boolean the you can simply use:
tfValue = Not Me.Qual_Complete

I would also simplify the code further. Name the controls to be Enabled starting with Qual and change the others. Replace the list of controls with this:

Code:
Dim ctrl as Control
 
For Each ctrl in Me
   If Left(ctrl.Name, 4) = "Qual" Then
      ctrl.Enabled = tfValue
   End If
Next

If you don't want to rename with a pattern then another way to select the controls to be affected is with the Tag property.
 

Users who are viewing this thread

Back
Top Bottom