Text box that updates a control IF it is EMPTY or Has Text

L

LilC

I have created a red and green radio button. For a quick visual look, I want
to be able to look at the form, which has multiple text boxes, to see if all
the information has been entered. If the text box is empty, the red radio
button is visible from the start. If the text box has the required info.,
the radio button (initial visibility set to false), becomes visible on the
form next to my text box. So, as the information is entered into the text
boxes, the red radio buttons change to green, indicating completed. In the
form current event I'm using

Private Sub Form_Current()
If Len(Nz(Me.FirstName, "")) > 0 Then
rdoRED.Visible = False
rdoGreen.Visible = True
Else
rdoRED.Visible = True
rdoGreen.Visible = False
End If
End Sub

This works fine. My Question, is there an easy way to do this if I have 50
text boxes? Or, do I have to do this same code for each text box? And can I
use the same two radio buttons as my indicators for multiple text boxes or do
I have to copy and rename the bottoms for each text box on my form?
 
J

Jeanette Cunningham

This does not directly answer your question, but . . .
You might find it quicker and easier to color the border of each text box
instead of using radio buttons.
That way you could write some code to change border color and use it for
each textbox.

You can put code on the after update event of each textbox to call the
function that changes the border color.
You can put code on the form's load event to loop through all the textboxes
and setup the border color.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
L

LilC via AccessMonster.com

Thank you for your response. I have been able to do as you have advised by
looping through all the text boxes which are empty and giving those empty
text boxes a unique color. I used this code which I found in this forum and
placed it in the Private Sub Form_Current.
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If IsNull(ctrl.Value) Then
ctrl.BackColor = vbRed
Else: ctrl.BackColor = vbWhite
End If
End If
Next
However, I am now just more curious than anything else to see the alternative
options by using the radio buttons. Could I replace the If TypeOf ctrl is
TextBox Then, with If Type of ctrl is Image Then? Also, what about the red
and green radio button actual names. It may not be worth the trouble.

Thank you so much for your help.

Jeanette said:
This does not directly answer your question, but . . .
You might find it quicker and easier to color the border of each text box
instead of using radio buttons.
That way you could write some code to change border color and use it for
each textbox.

You can put code on the after update event of each textbox to call the
function that changes the border color.
You can put code on the form's load event to loop through all the textboxes
and setup the border color.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
I have created a red and green radio button. For a quick visual look, I
want
[quoted text clipped - 25 lines]
do
I have to copy and rename the bottoms for each text box on my form?
 
J

Jeanette Cunningham

I have not used this type of code with radio buttons or images, but I
imagine it would work in a similar way.
The trickier thing about using radio buttons or images, is to know which
ones to make red - because you will need to know which textbox is null for
which radio button or which image.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


LilC via AccessMonster.com said:
Thank you for your response. I have been able to do as you have advised
by
looping through all the text boxes which are empty and giving those empty
text boxes a unique color. I used this code which I found in this forum
and
placed it in the Private Sub Form_Current.
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If IsNull(ctrl.Value) Then
ctrl.BackColor = vbRed
Else: ctrl.BackColor = vbWhite
End If
End If
Next
However, I am now just more curious than anything else to see the
alternative
options by using the radio buttons. Could I replace the If TypeOf ctrl is
TextBox Then, with If Type of ctrl is Image Then? Also, what about the
red
and green radio button actual names. It may not be worth the trouble.

Thank you so much for your help.

Jeanette said:
This does not directly answer your question, but . . .
You might find it quicker and easier to color the border of each text box
instead of using radio buttons.
That way you could write some code to change border color and use it for
each textbox.

You can put code on the after update event of each textbox to call the
function that changes the border color.
You can put code on the form's load event to loop through all the
textboxes
and setup the border color.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
I have created a red and green radio button. For a quick visual look, I
want
[quoted text clipped - 25 lines]
do
I have to copy and rename the bottoms for each text box on my form?
 
J

Jeanette Cunningham

You can use a special naming system to make it easier.

Create the textboxes and radio buttons or images with similar names
txt1, txt2, txt3
rb1, rb2, rb3,
img1, img2, img3

This is untested, but you could try something like
Dim num as long
For num = 1 to 10
If IsNull(Me.Controls("txt" & num) ) Then
Me.Controls("rb" & num).Backcolor = vbRed
End If
Next


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia






LilC via AccessMonster.com said:
Thank you for your response. I have been able to do as you have advised
by
looping through all the text boxes which are empty and giving those empty
text boxes a unique color. I used this code which I found in this forum
and
placed it in the Private Sub Form_Current.
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If IsNull(ctrl.Value) Then
ctrl.BackColor = vbRed
Else: ctrl.BackColor = vbWhite
End If
End If
Next
However, I am now just more curious than anything else to see the
alternative
options by using the radio buttons. Could I replace the If TypeOf ctrl is
TextBox Then, with If Type of ctrl is Image Then? Also, what about the
red
and green radio button actual names. It may not be worth the trouble.

Thank you so much for your help.

Jeanette said:
This does not directly answer your question, but . . .
You might find it quicker and easier to color the border of each text box
instead of using radio buttons.
That way you could write some code to change border color and use it for
each textbox.

You can put code on the after update event of each textbox to call the
function that changes the border color.
You can put code on the form's load event to loop through all the
textboxes
and setup the border color.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
I have created a red and green radio button. For a quick visual look, I
want
[quoted text clipped - 25 lines]
do
I have to copy and rename the bottoms for each text box on my form?
 
L

LilC via AccessMonster.com

Thanks again for your response. I'm going to try to use this. I have
already incorporated the other method in the text box itself, but I would
just like to see if the radio button method is that much more complex. Thank
you very much.


Jeanette said:
You can use a special naming system to make it easier.

Create the textboxes and radio buttons or images with similar names
txt1, txt2, txt3
rb1, rb2, rb3,
img1, img2, img3

This is untested, but you could try something like
Dim num as long
For num = 1 to 10
If IsNull(Me.Controls("txt" & num) ) Then
Me.Controls("rb" & num).Backcolor = vbRed
End If
Next

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
Thank you for your response. I have been able to do as you have advised
by
[quoted text clipped - 39 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top