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

Help with making a text box go back to white after it has been selected

P: 19
I have set up a procedure that checks the fields in a form and alerts you if a box has not been filled out and asks if you would like to complete the field. If you choose yes, it makes the textbox red and allows you to enter data in the text box.
I am having troubke getting the text box to return back to white after the field has been filled in. When this happens it also make the rest of the "same field in other records red as well. I only want the field that was not filled in to be red until the user enters something in it. Below is what I have done so far and it works other than it staying red. Can someone help me please?

For Each ctl In Me.Controls
If IsNull(ctl) Then
If ctl.Name <> "BreedSearch" Then
If ctl.Name <> "Breed Picture" Then
intResponse = MsgBox("A field has not been completed. Do you wish to complete the field?", vbYes + vbExclamation, "Missing Field")
If intResponse = vbYes Then
ctl.SetFocus
ctl.BackColor = 255
Exit Sub
End If
End If
End If
End If
Next ctl

DoCmd.GoToRecord , , acNext

End Sub
Nov 21 '06 #1
Share this Question
Share on Google+
6 Replies


Expert 5K+
P: 8,435
Expand|Select|Wrap|Line Numbers
  1.   For Each ctl In Me.Controls
  2.     If IsNull(ctl) Then
  3.       If ctl.Name <> "BreedSearch" Then
  4.         If ctl.Name <> "Breed Picture" Then
  5.           intResponse = MsgBox("A field has not been completed.  Do you wish to complete the field?", vbYes + vbExclamation, "Missing Field")
  6.           If intResponse = vbYes Then
  7.             ctl.SetFocus
  8.             ctl.BackColor = 255
  9.             Exit Sub
  10.           End If
  11.         End If
  12.       End If
  13.     End If
  14.   Next ctl
  15.   #### INSERT HERE ####
  16.   DoCmd.GoToRecord , , acNext
  17. End Sub
  18.  
Perhaps you could just set the background colour to normal at the point indicated?

By the way, one technique I have often used (in VB6, but may work in Access) is to place something in the .Tag property for each field you need to check, so your code can easily identify them. For example, rather than checking ctl.Name, you might do something like
Expand|Select|Wrap|Line Numbers
  1. if instr(ctl.Tag, "/NONULLS") Then
Then you just enter "/NONULLS" in the Tag property for any control you want this code to check. (Note, this also makes it easier to know which ones to change back to normal).
Nov 21 '06 #2

P: 19
Thank you but what code do I need to put in there to get the colour back to normal? I am not familiar with the code to put the colour back to white or normal.
Nov 21 '06 #3

Expert 5K+
P: 8,435
Thank you but what code do I need to put in there to get the colour back to normal? I am not familiar with the code to put the colour back to white or normal.
I wasn't thinking of anything complicated. Just ctl.BackColor = VbWhite, or whatever. I didn't know what you backcolor was, so didn't say.

Also, it might vary depending on the control type, plus you might need to check whether it is a control (or type of control) that you're interested in.
Nov 21 '06 #4

P: 19
I wasn't thinking of anything complicated. Just ctl.BackColor = VbWhite, or whatever. I didn't know what you backcolor was, so didn't say.

Also, it might vary depending on the control type, plus you might need to check whether it is a control (or type of control) that you're interested in.
When I enter that I get an error.
Run time error 91
Nov 21 '06 #5

Expert 5K+
P: 8,435
When I enter that I get an error.
Run time error 91
I don't recognise the error, but I'll take a stab in the dark - it's probably complaining because you're trying to change the backcolor property for a control that doesn't have one.

You might need to do it only for the relevant controls. As I said, there are various ways you can do this. Some examples:
  • If TypeOf <your control> Is TextBox Then ...
  • If Instr(<your control>.Tag,"<some flag you placed there>") Then ...
  • If <your control>.Name = <whatever you like> Then...
Nov 21 '06 #6

Expert 5K+
P: 8,435
Oops! Since it refers to ctl, it would also need to go inside the For Each ctl loop. I would try this first. (What I just said in my post a couple of minutes ago still applies, though).
Nov 21 '06 #7

Post your reply

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