By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Clear Error Message from TextBox

P: 15
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....
Expand|Select|Wrap|Line Numbers
  1. Private Sub FormCheckButton_Click()
  2. If TextboxA = "" Then
  3. ErrorBox = "TextBoxA cannot be blank, please enter value"
  4. 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.
Jul 25 '10 #1
Share this Question
Share on Google+
11 Replies


mseo
100+
P: 181
@Jonathan Austin
you can use something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Check1_Click()
  2. If Me.check1 = -1 Then
  3. Me.errorbox= ""
  4. DoCmd.OpenForm "your form name"
  5. Me.check1 = 0
  6. End If
  7. End Sub
  8.  
hope this helps
Jul 25 '10 #2

P: 15
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReviewButton_Click()
  2. If ComboBoxA = "" Then
  3. ErrorBoxA.Text = "ComboBoxA Cannot Be Blank, Answer Is Required"
  4. End If
  5.  
  6. If ComboBoxB = "" Then
  7. ErrorBoxA.Text = ErrorBoxA.Text & "ComboBoxB Cannot Be Blank, Answer Is Required"
  8. End If
  9.  
  10. If ComboBoxC = "" Then
  11. ErrorBoxA.Text = ErrorBoxA.Text & "ComboBoxC Cannot Be Blank, Answer Is Required"
  12. End If
  13.  
  14. 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?
Jul 25 '10 #3

mseo
100+
P: 181
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?
Jul 25 '10 #4

P: 15
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.
Jul 25 '10 #5

P: 15
@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.
Jul 25 '10 #6

mseo
100+
P: 181
@Jonathan Austin
So, It would be like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me!Text1) Then
  3. Me.Text2 = "text 1 is blank, it is required"
  4. Cancel = True: Me.Text1.SetFocus
  5. ElseIf Not IsNull(Me.Text1) Then
  6. Me.Text2 = ""
  7. End If
  8. If IsNull(Me!T5) Then
  9. Me.T6 = "text 5 is blank, it is required"
  10.  Cancel = True: Me.T5.SetFocus
  11. ElseIf Not IsNull(Me.T5) Then
  12. Me.T6 = ""
  13. End If
  14. End Sub
  15.  
in the demo, generate an ID and try to move to the next record
hope this helps
Attached Files
File Type: zip demo.zip (41.6 KB, 77 views)
Jul 25 '10 #7

P: 15
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
File Type: zip Demo.zip (36.7 KB, 80 views)
Jul 25 '10 #8

NeoPa
Expert Mod 15k+
P: 31,769
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....
Expand|Select|Wrap|Line Numbers
  1. Private Sub FormCheckButton_Click()
  2. If TextboxA = "" Then
  3. ErrorBox = "TextBoxA cannot be blank, please enter value"
  4. 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 :
Expand|Select|Wrap|Line Numbers
  1. Private Sub FormCheckButton_Click()
  2.     ErrorBox = IIf(IsNull(Me.TextBoxA), _
  3.                    "TextBoxA cannot be blank, please enter value", _
  4.                    Null)
  5. End If
I'd suggest rather that this code be put in TextBoxA_AfterUpdate() though, unless you have a good reason for wanting to make the operator work to get the response.
Jul 25 '10 #9

NeoPa
Expert Mod 15k+
P: 31,769
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.
Jul 25 '10 #10

NeoPa
Expert Mod 15k+
P: 31,769
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.
Jul 25 '10 #11

mseo
100+
P: 181
@NeoPa
that's true Neopa, We have learned a lot of things from here
thank you
Jul 26 '10 #12

Post your reply

Sign in to post your reply or Sign up for a free account.