Clear Error Message from TextBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan Austin
    New Member
    • Jul 2010
    • 15

    Clear Error Message from TextBox

    Ok I got it now, thank you everyone for that. Now I have another question. I'm creating an error report from, if a textbox is blank then it'll display a text in another textbox stating "Textbox is blank, please enter a value" etc... So it will look something like this....
    Code:
    Private Sub FormCheckButton_Click()
    If TextboxA = "" Then
    ErrorBox = "TextBoxA cannot be blank, please enter value"
    End If
    Now when TextBoxA is answered, and when the FormCheckButton is clicked for another form review, how do I remove the "TextBoxA cannot be blank, please enter value" message from the ErrorBox? Hopefully all this made sense.

    ** Edit **
    This question was asked in another thread (What is the VB code for looking up a value in a table?). Please post new questions in their own threads in future.
    Last edited by NeoPa; Jul 25 '10, 05:13 PM. Reason: Please use the [CODE] tags provided
  • mseo
    New Member
    • Oct 2009
    • 183

    #2
    Originally posted by Jonathan Austin
    Ok I got it now, thank you everyone for that. Now I have another question. I'm creating an error report from, if a textbox is blank then it'll display a text in another textbox stating "Textbox is blank, please enter a value" etc... So it will look something like this....

    Private Sub FormCheckButton _Click()
    If TextboxA = "" Then
    ErrorBox = "TextBoxA cannot be blank, please enter value"
    End If

    Now when TextBoxA is answered, and when the FormCheckButton is clicked for another form review, how do I remove the "TextBoxA cannot be blank, please enter value" message from the ErrorBox? Hopefully all this made sense.
    you can use something like this:
    Code:
    Private Sub Check1_Click()
    If Me.check1 = -1 Then
    Me.errorbox= ""
    DoCmd.OpenForm "your form name"
    Me.check1 = 0
    End If
    End Sub
    hope this helps

    Comment

    • Jonathan Austin
      New Member
      • Jul 2010
      • 15

      #3
      Unfortunately that won't, because my error box will be compiled with other text, so I just want to eliminate certain text. I'll write it out for better understanding.
      Code:
      Private Sub ReviewButton_Click()
      If ComboBoxA = "" Then
      ErrorBoxA.Text = "ComboBoxA Cannot Be Blank, Answer Is Required"
      End If
      
      If ComboBoxB = "" Then
      ErrorBoxA.Text = ErrorBoxA.Text & "ComboBoxB Cannot Be Blank, Answer Is Required"
      End If
      
      If ComboBoxC = "" Then
      ErrorBoxA.Text = ErrorBoxA.Text & "ComboBoxC Cannot Be Blank, Answer Is Required"
      End If
      
      End Sub
      ErrorBoxA should read,
      ErrorBoxA: ComboBoxA Cannot Be Blank, Answer Is Required
      ComboBoxB Cannot Be Blank, Answer Is Required
      ComboBoxC Cannot Be Blank, Answer Is Required

      I want to know, if ComboBoxB IS NOT blank, what would be the code to remove the "ComboBoxB Cannot Be Blank, Answer Is Required" text from ErrorBoxA while leaving the rest?
      Last edited by NeoPa; Jul 25 '10, 05:19 PM. Reason: Please use the [CODE] tags provided

      Comment

      • mseo
        New Member
        • Oct 2009
        • 183

        #4
        so, you want to prevent any of the comboboxes from being null or blank , and want to view the messages in textbox istead of msgbox, is that right?

        Comment

        • Jonathan Austin
          New Member
          • Jul 2010
          • 15

          #5
          Yes thats correct, after my personnel enter information, (its alot of information to be enter, so there will be entries that may be over looked.) So any blank entries I want the errors to show up as text in the error boxes (error boxes = textboxes) not msgbox.

          Comment

          • Jonathan Austin
            New Member
            • Jul 2010
            • 15

            #6
            Originally posted by Jonathan Austin
            Yes thats correct, after my personnel enter information, (its alot of information to be enter, so there will be entries that may be over looked.) So any blank entries I want the errors to show up as text in the error boxes (error boxes = textboxes) not msgbox.
            - I could have all the fields required, but it would be annoying to hear 'dings' after each one, which by the way, all entries are required.

            Comment

            • mseo
              New Member
              • Oct 2009
              • 183

              #7
              Originally posted by Jonathan Austin
              - I could have all the fields required, but it would be annoying to hear 'dings' after each one, which by the way, all entries are required.
              So, It would be like this:
              Code:
              Private Sub Form_BeforeUpdate(Cancel As Integer)
              If IsNull(Me!Text1) Then
              Me.Text2 = "text 1 is blank, it is required"
              Cancel = True: Me.Text1.SetFocus
              ElseIf Not IsNull(Me.Text1) Then
              Me.Text2 = ""
              End If
              If IsNull(Me!T5) Then
              Me.T6 = "text 5 is blank, it is required"
               Cancel = True: Me.T5.SetFocus
              ElseIf Not IsNull(Me.T5) Then
              Me.T6 = ""
              End If
              End Sub
              in the demo, generate an ID and try to move to the next record
              hope this helps
              Attached Files

              Comment

              • Jonathan Austin
                New Member
                • Jul 2010
                • 15

                #8
                Actually I figured out what I needed, I'll post it, it may help others on this. Its basically like creating your own verison of an error report.

                Check this out
                Attached Files

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32633

                  #9
                  Originally posted by Jonathan Austin
                  Jonathan Austin: Ok I got it now, thank you everyone for that. Now I have another question. I'm creating an error report from, if a textbox is blank then it'll display a text in another textbox stating "Textbox is blank, please enter a value" etc... So it will look something like this....
                  Code:
                  Private Sub FormCheckButton_Click()
                  If TextboxA = "" Then
                  ErrorBox = "TextBoxA cannot be blank, please enter value"
                  End If
                  Now when TextBoxA is answered, and when the FormCheckButton is clicked for another form review, how do I remove the "TextBoxA cannot be blank, please enter value" message from the ErrorBox? Hopefully all this made sense.
                  The simple answer to this is :
                  Code:
                  Private Sub FormCheckButton_Click()
                      ErrorBox = IIf(IsNull(Me.TextBoxA), _
                                     "TextBoxA cannot be blank, please enter value", _
                                     Null)
                  End If
                  I'd suggest rather that this code be put in TextBoxA_AfterU pdate() though, unless you have a good reason for wanting to make the operator work to get the response.

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32633

                    #10
                    Originally posted by Jonathan Austin
                    Jonathan Austin: Actually I figured out what I needed, I'll post it, it may help others on this.
                    As a general rule yes. On the other hand posting an attachment as a solution on a forum like this is pretty much a waste of time.

                    If people are scanning through web pages to see if they've found something that can help them they want to be able to see it without downloading, opening, navigating to the relevant part, etc before they see what they're after.

                    Attachments are for things a little more complicated than simple concepts easily shown in a few lines of code.

                    Please feel free to post your solution if you think it will help. We are always pleased to see such responses. Particularly from those that ask the question in the first place, as it indicates they've learned something from visiting Bytes, which is fundamentally what we are aiming for.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      As the question has changed from the original one (to include the idea that multiple error messages are included in the TextBox) I will suggest a more appropriate alternative. At least I will outline the concept for now. The previous code indicates some of what is required as building blocks.

                      Firstly, each control that has the potential for producing an error message in [TextBoxA] would need an AfterUpdate event procedure which calls a separate procedure, we'll call this UpdateError(), that works out what the contents of that control should be. There would be code within UpdateError() to handle each of the said controls. For each control there would be code, similar to that found in post #9, to set or clear the part related to that control depending on the current contents of the control.

                      Separating each message from the next would be done by including the inbuilt value vbNewLine. Only required for controls that actually trigger error messages of course.

                      Comment

                      • mseo
                        New Member
                        • Oct 2009
                        • 183

                        #12
                        Originally posted by NeoPa
                        Particularly from those that ask the question in the first place, as it indicates they've learned something from visiting Bytes, which is fundamentally what we are aiming for.
                        that's true Neopa, We have learned a lot of things from here
                        thank you

                        Comment

                        Working...