Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2007
    Posts
    102

    Unanswered: Clear controls on a subform

    Hello experts,


    Does anyone have a simple method to use behind a command button that would clear all controls on 1 subform without using a SetFocus routine?

    After clear, then return control to the main form?

    thanks

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Can't we apply the same method to the subform that we have done in the past with your main form?
    Code:
    Forms!mySubForm.ControlName.Value = "" 'Or Null?
    Stick that in a loop and smoke it
    George
    Home | Blog

  3. #3
    Join Date
    Aug 2007
    Posts
    102

    It would be great if I could

    The problem is 2 of the controls contain expressions, so I can't set them to Null without the compiler complaining.


    So with this:
    Code:
    Forms![Order Details Subform].SubTotal.Value = "" (or Null)
    it doesn't like this either:
    Code:
    Forms![Add an Order and Details]![Order Details Subform].ProductID.Value = "" (or Null)
    or this:
    Code:
    Forms![Add an Order and Details]![Order Details Subform]!Form.Quantity.Value = "" (or Null)
    I just changed the names of my subforms (to remove spaces inthe name) to OrderDetails....
    can't smoke it yet George
    Last edited by imrosie; 09-20-07 at 12:27.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quelles sont les expressions?
    George
    Home | Blog

  5. #5
    Join Date
    May 2003
    Location
    Dallas
    Posts
    817
    Provided Answers: 5

    you could use

    mycontrol.ControlSource = Nz(Null, "")

    that would clear the expression for that instance and then you could reset it
    txtPromisedTime.ControlSource = myexpression

    does that sound right Geo?
    Dale Houston, TX

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    mycontrol.ControlSource = Nz(Null, "")
    Is the equivalent of
    Code:
    mycontrol.ControlSource = ""
    Because Nz(Null,"") Will always return two double quotes ("")...
    George
    Home | Blog

  7. #7
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I would suggest using the Tag property of the controls you want to clear. In the subform set the Tag property to 1 for all the controls you want to clear. Then use a For Each loop to clear only those controls where the Tag is 1.

    Here is some code:

    Code:
        Dim varControl As Variant
                
        For Each varControl In Me.Subform.Form.Controls
        
            If varControl.ControlType = acTextBox Or varControl.ControlType = acLabel Then
                
                If varControl.Tag=1 Then
                    
                        varControl = ""
                    
                End If
                
            End If
                
        Next varControl
    I added a check to see if the control was a textbox or label. This may or may not apply to you.

  8. #8
    Join Date
    Aug 2007
    Posts
    102

    Thanks so much

    I will try this out and definitely report back...thanks to you all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •