Me.Checkbox Script in VB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bgaye1979
    New Member
    • Nov 2007
    • 4

    Me.Checkbox Script in VB

    I have a form and there is a Yes/No Checkbox as a datatype. This field is called FileReturned. There is another field called ReturnedDate.

    If the ReturnedDate field is Null, I want the checkbox to be unchecked automatically, else the checkbox should be checked. Can someone help me with the code and where to write it? Should it be on the form's current event or before update?

    Here's it what i have?

    If ReturnedDate is Null Then
    Me.FileReturned = False
    Else
    Me.FileReturned =True
    End If
  • benchpolo
    New Member
    • Sep 2007
    • 142

    #2
    You can place the code in several event OnFormLoad, OnBeforeUpdate, OnAfterUpdate, OnClick, OnDoubleClick, OnFocus, OnLostFocus depending on the requirements on your specs.

    Comment

    • bgaye1979
      New Member
      • Nov 2007
      • 4

      #3
      Originally posted by benchpolo
      You can place the code in several event OnFormLoad, OnBeforeUpdate, OnAfterUpdate, OnClick, OnDoubleClick, OnFocus, OnLostFocus depending on the requirements on your specs.
      Thank you. I did but the code didn't work. Any idea?

      Comment

      • zimitry
        New Member
        • May 2007
        • 11

        #4
        There's a few ways todo this here's one...

        Code:
        Private Sub txtbox1_AfterUpdate()
        
            If IsNull(Me.txtbox1) And Me.chkbox1 = True Then
                Me.chkbox1.Value = False
            Else
                'Do nothing
            End If
        
        End Sub
        
        Private Sub txtbox1_Exit(Cancel As Integer)
        
            If IsNull(Me.txtbox1) And Me.chkbox1 = True Then
                Me.chkbox1.Value = False
            Else
                'Do nothing
            End If
        
        End Sub
        HTH

        z

        Comment

        • bgaye1979
          New Member
          • Nov 2007
          • 4

          #5
          Thank you for the assistance. I tried it as you said but the checkbox is not updated( or checked automatically) for records where the ReturnedDate is Not Null with the code below;

          Private Sub ReturnedDate_Af terUpdate()
          If IsNull(Me.Retur nedDate) And Me.FileReturned = True Then
          Me.FileReturned .Value = False
          Else
          'do nothing
          End If
          End Sub

          Do you have any further assistance?


          Originally posted by zimitry
          There's a few ways todo this here's one...

          Code:
          Private Sub txtbox1_AfterUpdate()
          
              If IsNull(Me.txtbox1) And Me.chkbox1 = True Then
                  Me.chkbox1.Value = False
              Else
                  'Do nothing
              End If
          
          End Sub
          
          Private Sub txtbox1_Exit(Cancel As Integer)
          
              If IsNull(Me.txtbox1) And Me.chkbox1 = True Then
                  Me.chkbox1.Value = False
              Else
                  'Do nothing
              End If
          
          End Sub
          HTH

          z

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            hi there you want to put this code in the forms current event like this

            Code:
            Private Sub Form_Current()
                
                If IsNull(returneddate) Then
                    filereturned = False
                Else
                    filereturned = True
                    
                End If
                
            End Sub
            i hope this is what you were trying to do.

            lee123

            Comment

            • bgaye1979
              New Member
              • Nov 2007
              • 4

              #7
              Thank you so much. It worked perfectly fine.
              Originally posted by lee123
              hi there you want to put this code in the forms current event like this

              Code:
              Private Sub Form_Current()
                  
                  If IsNull(returneddate) Then
                      filereturned = False
                  Else
                      filereturned = True
                      
                  End If
                  
              End Sub
              i hope this is what you were trying to do.

              lee123

              Comment

              • lee123
                Contributor
                • Feb 2007
                • 556

                #8
                glade to help

                lee123

                Comment

                Working...