Help in clearing form data!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32645

    #16
    Originally posted by mmccarthy
    Speak for yourself. I always knew everything. I was programmed that way :D
    Fair point Mary.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #17
      Originally posted by NeoPa
      Fair point Mary.
      Don't think I didn't notice the edit. How double damn dare you. :D

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #18
        Originally posted by mmccarthy
        Don't think I didn't notice the edit. How double damn dare you. :D
        Well - it was worth a try :D (I didn't tamper with your post notice).

        Comment

        • Phille
          New Member
          • Jan 2007
          • 22

          #19
          Hi again

          So! I haven't yet receved my book so mean while I'm still stuck knowing a little less than nothing about VBA programming.

          Could there be anything done about the code giving an error when there are controlled objects on the form. For the moment I have a textbox that gets data depending of values from other controls. For example just ignoring those objects.

          Thanks in advance

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #20
            I've changed the original code somewhat. Considering this is a function to clear unbound controls, it's only right that there should be a check to see if the control is unbound ;)
            See if this works better for you.
            Code:
            'ClearUnbound empties all controls on an unbound form.
            Public Sub ClearUnbound(frmMe As Form)
                Dim varCtrl As Variant
            
                For Each varCtrl In frmMe.Controls
                    With varCtrl
                        Select Case .ControlType
                        Case acCheckBox, acComboBox, acListBox, acTextBox
                            If IsNull(.ControlSource) Then .Value = Null
                        End Select
                    End With
                Next varCtrl
            End Sub

            Comment

            • Phille
              New Member
              • Jan 2007
              • 22

              #21
              Thanks for the response but now it dosen't clear anything??
              Any other suggestions?

              Thanks

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #22
                Sorry. I expect the check of (.ControlSource ) should be for an empty string rather than Null. Try this amended version :
                Code:
                'ClearUnbound empties all controls on an unbound form.
                Public Sub ClearUnbound(frmMe As Form)
                    Dim varCtrl As Variant
                
                    For Each varCtrl In frmMe.Controls
                        With varCtrl
                            Select Case .ControlType
                            Case acCheckBox, acComboBox, acListBox, acTextBox
                                If .ControlSource = "" Then .Value = Null
                            End Select
                        End With
                    Next varCtrl
                End Sub

                Comment

                • Phille
                  New Member
                  • Jan 2007
                  • 22

                  #23
                  IT WORKS!!!

                  Thanks a million : )

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32645

                    #24
                    Everyone sounds surprised when my code works! :D

                    Seriously, I'm pleased it's done the trick.

                    Comment

                    Working...