Empty Textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beany
    New Member
    • Nov 2006
    • 173

    Empty Textbox

    Hi,

    i have a subform within a form.

    i have a combobox in the form that populates the subform after a selection.

    i have two textboxes that show some info from the subform, ie Number of items and User...

    How do i make sure that the textboxes are empty before i select a user from the combobox???

    My subform shows all records before i select a user from the combobox and the two fields show the info of the top record, which i dont want it to...

    any help will be appreicated
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    Originally posted by Beany
    Hi,

    i have a subform within a form.

    i have a combobox in the form that populates the subform after a selection.

    i have two textboxes that show some info from the subform, ie Number of items and User...

    How do i make sure that the textboxes are empty before i select a user from the combobox???

    My subform shows all records before i select a user from the combobox and the two fields show the info of the top record, which i dont want it to...

    any help will be appreicated
    Are these text boxes on your main form or your subform?

    What's the SQL for the query that populates your subform?

    Regards,
    Scott

    Comment

    • Beany
      New Member
      • Nov 2006
      • 173

      #3
      Originally posted by Scott Price
      Are these text boxes on your main form or your subform?

      What's the SQL for the query that populates your subform?

      Regards,
      Scott
      The textboxes are on the main form.

      my SQL for subform is:
      Code:
      SELECT Asset.ID, Asset.Asset, Asset.[Product Type], Asset.Manufacturer, Asset.Description, Asset.[Model No], Asset.[Serial No], Asset.[Windows Key], Asset.User, Asset.Department, Asset.Location, Asset.[Comms Date], Asset.Returned, Asset.[Return Reason] FROM Asset;

      Comment

      • Stwange
        Recognized Expert New Member
        • Aug 2007
        • 126

        #4
        If your textboxes are unbound, and you want to clear ALL of the text fields on that form, run the following code somewhere in that form, possible on the combobox_click( ):
        Code:
        Dim obj As Object
        For Each obj In Me
            If TypeName(obj) = "TextBox" Then obj.Value = ""
        Next obj
        Hope this helps.

        Comment

        • Beany
          New Member
          • Nov 2006
          • 173

          #5
          the code you provided, will this only clear the textboxes when i select something from the combobox?

          i want it to stay clear from the start and once ive selected a user from the combobox it should show the appropriate info..

          does this make sense :)

          Comment

          • Stwange
            Recognized Expert New Member
            • Aug 2007
            • 126

            #6
            Originally posted by Beany
            the code you provided, will this only clear the textboxes when i select something from the combobox?

            i want it to stay clear from the start and once ive selected a user from the combobox it should show the appropriate info..

            does this make sense :)
            Then you should put it in form load, and possible again on combobox_afterU pdate before the fields will be updated by your code somewhere else

            Comment

            • Beany
              New Member
              • Nov 2006
              • 173

              #7
              ive tried this,

              but its not doing anything!

              Comment

              • Stwange
                Recognized Expert New Member
                • Aug 2007
                • 126

                #8
                Originally posted by Beany
                ive tried this,

                but its not doing anything!
                Where are you running it? The ME in there means it must be the current form, not a sub form.

                Comment

                • Beany
                  New Member
                  • Nov 2006
                  • 173

                  #9
                  Originally posted by Stwange
                  Where are you running it? The ME in there means it must be the current form, not a sub form.

                  im running it on the form....not the subform..

                  for some reason it wont work....

                  Text20 is the textbox (in the form) which shows the name of the person in the subform.. (Name of person is shown by selecting it from a combobox in the form)

                  in the subform footer , theres a textbox called 'txtCountUser' and calculates the amount of users in the subform. Text20 displays the info of txtCountUser.

                  If i open the form, the subform shows all records (which is ok) but Text20 is showing the top record of the subform, but i dont want this...

                  i just want Text20 to be empty until i select someone from the combo..

                  sorry for the confusion..:(

                  Comment

                  • Stwange
                    Recognized Expert New Member
                    • Aug 2007
                    • 126

                    #10
                    Originally posted by Beany
                    im running it on the form....not the subform..

                    for some reason it wont work....

                    Text20 is the textbox (in the form) which shows the name of the person in the subform.. (Name of person is shown by selecting it from a combobox in the form)

                    in the subform footer , theres a textbox called 'txtCountUser' and calculates the amount of users in the subform. Text20 displays the info of txtCountUser.

                    If i open the form, the subform shows all records (which is ok) but Text20 is showing the top record of the subform, but i dont want this...

                    i just want Text20 to be empty until i select someone from the combo..

                    sorry for the confusion..:(
                    If you only want text20 to be empty, try doing: Text20.value = "", and put it in Form_Load() not Form_Open()
                    If this doesn't work, something is filling the text box back in, is it bound to something? Is there a loop somewhere in the sub form that might be filling it? Are you sure it is unbound?

                    Good luck.

                    Comment

                    • Scott Price
                      Recognized Expert Top Contributor
                      • Jul 2007
                      • 1384

                      #11
                      Just checking, your text boxes are unbound, or bound?

                      Regards,
                      Scott

                      Comment

                      • Beany
                        New Member
                        • Nov 2006
                        • 173

                        #12
                        Originally posted by Scott Price
                        Just checking, your text boxes are unbound, or bound?

                        Regards,
                        Scott
                        Sorry, but the textboxes are bound. Ive tried inserting
                        Code:
                        Text20.value = ""
                        in on_load event procedure of the form but i get the following error:

                        Run-time error '2448': You can't assign a value to this object

                        Text20 displays the info from the textbox txtCountUser.

                        txtCountUser is in the subform footer

                        Comment

                        • Stwange
                          Recognized Expert New Member
                          • Aug 2007
                          • 126

                          #13
                          Originally posted by Beany
                          Sorry, but the textboxes are bound. Ive tried inserting
                          Code:
                          Text20.value = ""
                          in on_load event procedure of the form but i get the following error:

                          Run-time error '2448': You can't assign a value to this object

                          Text20 displays the info from the textbox txtCountUser.

                          txtCountUser is in the subform footer
                          This might sound like a daft question, but are you sure Text20 is a text box? I'm only asking because, if you copied that code from your editor, the value should have a capital V, ie. .Value (this would have been done automatically from the editor)

                          Also, setting a bound text box to "" is a bad idea, unless you want to remove the corresponding field in the table. Please tell me exactly what this text box is supposed to achieve, if it is just echoing information from another text box, it shouldn't be bound, but if it needs to be linked to the database, you shouldn't be emptying it. Maybe your question isn't how to blank a textbox, but more, how to open a blank record when the form is opened.

                          I need more information (unless anyone can see anything wrong with what I've done so far?)

                          Thanks.

                          Comment

                          • Stwange
                            Recognized Expert New Member
                            • Aug 2007
                            • 126

                            #14
                            Originally posted by Stwange
                            This might sound like a daft question, but are you sure Text20 is a text box? I'm only asking because, if you copied that code from your editor, the value should have a capital V, ie. .Value (this would have been done automatically from the editor)

                            Also, setting a bound text box to "" is a bad idea, unless you want to remove the corresponding field in the table. Please tell me exactly what this text box is supposed to achieve, if it is just echoing information from another text box, it shouldn't be bound, but if it needs to be linked to the database, you shouldn't be emptying it. Maybe your question isn't how to blank a textbox, but more, how to open a blank record when the form is opened.

                            I need more information (unless anyone can see anything wrong with what I've done so far?)

                            Thanks.
                            I think you editted that post after I saw it. If Text20 is linked to another textbox, this isn't (really) the same as being bound. Is it bound to the same value as the other textbox, (ie the same field in the table), or does it simply display the value of the textbox (ie. the control source is something like [Forms]![yourSubForm]![someOtherTextBo x].Value

                            Comment

                            • Beany
                              New Member
                              • Nov 2006
                              • 173

                              #15
                              Okay,

                              Ive attached an image of my database.

                              If you look at it, theres an Item Holder textbox (Text20). This is what it looks like when i open the form. It shows the top value in the subform.

                              Also, on opening the subform it shows all records.

                              I want the textbox to be empty until i select something from the comboboxes.

                              Text20 is definitely a textbox and its bound. Info is extracted from a Count Textbox in the subform footer....
                              Attached Files

                              Comment

                              Working...