Repaint onCurrent not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KatcDolly
    New Member
    • Sep 2016
    • 15

    Repaint onCurrent not working

    I am going to open a new discussion that refers back to this pervious one.



    I have code that runs for fields to be visible and invisible in my form. It is all working except when I move to a new record. The "repaint" is not working in the OnCurrent part of the form.

    I have tried moving it around, but does not seem to be working. Any help would be appreciated.

    Thanks
    Attached Files
    Last edited by KatcDolly; Sep 9 '16, 03:53 PM. Reason: I added the db I am working in for ease.
  • jforbes
    Recognized Expert Top Contributor
    • Aug 2014
    • 1107

    #2
    I would take a slightly different approach. I would Enable and Disable your fields instead of Hiding or Showing them as it's usually easier on your users.

    I would also move all the enable/disable code into one function where everything is Disabled to start with and then Enabled as needed. It will be easier to maintain and troubleshoot. Make sure you set all your fields Visible property to True. Then use this code or something similar:
    Code:
    Private Sub Form_Current()
        Call enableDisable
    End Sub
    Private Sub opgHowLate_AfterUpdate()
        Call enableDisable
    End Sub
    Private Sub opgVisitType_AfterUpdate()
        Call enableDisable
    End Sub
    
    Private Sub enableDisable()
        
        Me.ckbFastTrackPaper.Enabled = False
        Me.ckbEvalShortTreat.Enabled = False
        Me.ckbEvalOnly.Enabled = False
        Me.ckbReschedule.Enabled = False
        Me.opgRescheduleWhen.Enabled = False
        Me.opgRescheduleProvider.Enabled = False
    
        Select Case Me.opgVisitType
            Case 1
                Select Case Me.opgHowLate
                    Case 1
                        Me.ckbFastTrackPaper.Enabled = True
                    
                    Case 2
                        Me.ckbEvalShortTreat.Enabled = True
                        Me.ckbEvalOnly.Enabled = True
                        Me.ckbReschedule.Enabled = True
                        Me.opgRescheduleWhen.Enabled = True
                        Me.opgRescheduleProvider.Enabled = True
                    
                    Case 3
                        Me.ckbEvalOnly.Enabled = True
                        Me.ckbReschedule.Enabled = True
                        Me.opgRescheduleWhen.Enabled = True
                        Me.opgRescheduleProvider.Enabled = True
                End Select
            Case 2
                Me.ckbShorterVisit.Enabled = True
                Select Case Me.opgHowLate
                    Case 2 Or 3
                        Me.ckbReschedule.Enabled = True
                        Me.opgRescheduleWhen.Enabled = True
                        Me.opgRescheduleProvider.Enabled = True
                        
                End Select
        End Select
        
    End Sub
    Hopefully I got everything to enable and disable as needed, you may need to tweak the code if a control doesn't turn on when you expect it to.

    Comment

    • KatcDolly
      New Member
      • Sep 2016
      • 15

      #3
      I just had a conversation with someone about considering doing it with Enable/Disable. So Thank you!


      Thanks also for the awesome examples and where to do things. I feel like I learned a great deal from you! It feels good!
      Last edited by KatcDolly; Sep 10 '16, 01:20 PM. Reason: In the respecting the idea of keeping a thread per topic. I moved this issue to a new post.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Sometimes I find it easier to set the enabled of a single control at a time, instead of as a group with statements like:
        Code:
        Me.ckbFastTrackPaper.Enabled=(Me.opgVisitType=1 and Me.opgHowLate=1)
        
        Me.ckbEvalShortTreat.Enabled=(Me.opgVisitType=1 and Me.opgHowLate=2)
        I personally find the logic easier to follow, than the nested Case statements, but that might just be a matter of preference.

        Comment

        • KatcDolly
          New Member
          • Sep 2016
          • 15

          #5
          Thanks!

          It does make it easier to understand. I did not know you could do it that way.

          I appreciate you showing me this.

          Comment

          • jforbes
            Recognized Expert Top Contributor
            • Aug 2014
            • 1107

            #6
            That's a really good point!

            It's often preferable to list the control only once. Another thing to consider when using this method is to load most or all values on the Form that are being referred to into variables. That way they are only being accesses once and the code will get even easier to read. To build on what Smiley has provided:
            Code:
            Private Sub enableDisable
            
                Dim bEvalVisit As Boolean
                Dim iHowLate as Integer
                
                bEvalVisit = (Me.opgVisitType=1)
                iHowLate = Me.opgHowLate
            
                Me.ckbFastTrackPaper.Enabled=(bEvalVisit And iHowLate=1)
                Me.ckbEvalShortTreat.Enabled=(bEvalVisit And iHowLate=2)
            ...

            Comment

            Working...