473,467 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

19 New Member
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
6 1281
Killer42
8,435 Recognized Expert Expert
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
ducky
19 New Member
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
Killer42
8,435 Recognized Expert Expert
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
ducky
19 New Member
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
Killer42
8,435 Recognized Expert Expert
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
Killer42
8,435 Recognized Expert Expert
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

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

Similar topics

0
by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
9
by: Tristán White | last post by:
Hi I am very new to PHP - actually, this is my second day at it, as I've only recently started a new job last week. We're a charity. I have a "No input file selected" problem. A Google search...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
47
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
2
by: thuythu | last post by:
Please help me.... I used and Javascript to view the data. But when i click button open a popup windows, then select data and click save button. The popup close and return the main page, but the...
0
by: richard12345 | last post by:
Hi Guys I have problem with site I am building. The sidebar with menu and other thinks is overlapping footer. The footer move with the content and but it dos it dos not move with the sidebar. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.