vba code to turn on test boxes (1 Viewer)

Tupacmoche

Registered User.
Local time
Today, 05:44
Joined
Apr 28, 2008
Messages
291
Hi Form Masters,

I have several unbound text boxes that I have placed underneath several other textboxes. The ones underneath have the code ChrW("&H2714") which is the symbol for a check Mark as there Default Value. They all have there Visible method set to False (so they are invisible). The point is that as a user enters values into the textbox above them the check becomes visible since data has been entered. Here is the code that I put into the On Current event of the form:

'Turn on check marks.
If Nz(Len(Me.txtWriter.Value)) > 1 Or Nz(Len(Me.Draft_Date.Value)) > 1 Or Nz(Len(Me.DEC_Review_1.Value)) > 1 _
Or Nz(Len(Me.GO_Review.Value)) > 1 Or Nz(Len(Me.DEC_Review_2.Value)) > 1 Or Nz(Len(Me.GYK_Review.Value)) > 1 _
Or Nz(Len(Me.Signed_Mailed.Value)) > 1 Then
Me.TxtW.Visible = True
Me.TxtDD.Visible = True
Me.TxtDR1.Visible = True
Me.TxtGR.Visible = True
Me.TxtDR2.Visible = True
Me.TxtGYK.Visible = True
Me.TxtSC.Visible = True
Me.Refresh
Else
End If

It simple checks that there is something in the textbox and turns it on. Otherwise it should stay off. But they stay on all the time. Can anyone see what, I doing wrong?:eek:
 
Code is run by events. To trigger the code you need to associate it with one of the events.

So in this case you would probably want the after update event of the text box which holds the values to operate the check box?

Now the problem is if you navigate through records in the form, then the checkboxes will remain blank even if there is data in the text boxes, because there's nothing to trigger the code. In this case you would use the current event of the form which triggers when you change from one record to another.

In plain speaking terms when you enter data in the textbox you want the checkbox to be checked.

If a text box is emptied do you want the checkbox to vanish?

Do you want to signal that the text box contains something when you navigate from one record to another?






Sent from my SM-G925F using Tapatalk
 
here's an example using a loop and the controls tag property.
 

Attachments

Uncle Gizmo,

To answer your questions, I want the 'check' in the textbox to turn off if the corresponding textbox above it is empty. So the code Nz(Len(Me.txtWriter.Value)) > 1 checks to see if the string is greater than one and if it is the check is turned on otherwise it stays off. As, I navigate from record to record, I want the check to turn on or off based on data being entered into the corresponding textbox. This is like the UPS (United Postal Service) page that shows the progress of a package.
 
To get you started have a look on my website here:-

Loop Through a Set of Controls

Although I suspect that Moke has already provided you an answer along these particular Lines...

In the meantime I will see if I can construct a sample database...
 
Uncle Gizmo,

Nice video UG but what if you have dozens of controls of all sorts on a form how do you loop through a set of 10?
 
>>> but what if you have dozens of controls <<<

Then you need to identify the Controls. You have to mark them somehow so that your code can check to see if the control belongs to the particular set of controls you want to check. A typical way of doing this is to put an "X" in the Tag property of a Control, then you examine the Tag property looking to see if it has an "X", if it does you check that control if it does not have an X in it you ignore it.

Let's say you had three distinct groups of controls, and you wanted to check each group separately. Then you would put "X" in the Tag of one group "Y" in another group and "Z" in another group. In a more complicated scenario let's say you were already using Tag property for something else and couldn't use it as an identifier, then you could add some characters into the control name...

Let's say your control name was "txtProduct" you might have the identifier here:-"txtXProduct"

I've done a set of videos that go into it in Greater detail HERE:- Lock, Unlock Controls --- I also use a "Class Module" in one of the later examples.

See below:-
About the Simulated Option Group - I intend to add this method of using a frame around a set of controls to my blog post on - "Lock, Unlock Controls" but development is stalled at the moment! - Watch this space!

Something interesting to look at, if you create an option group on a Form, now drag one of the option Buttons out of the frame and it no longer works within the option group. In other words the option group selections are defined by the frame they are within.

I am writing some code to mimic this, in other words it checks the positions of the controls and you can tell if they are within a particular frame/rectangle/box. So you put a frame on the form, around a set of controls and you can have those controls behave as one set, very similar to an Option Group.

I've proved the basic Concept, and have a working model but it's not yet ready!

You can see it working in these videos here:-

Simulated Option Group - Nifty Access

Simulated Option Group Setup 1 - Nifty Access

Simulated Option Group Setup 2 - Nifty Access
 
Last edited:
let's say you were already using Tag property for something else
In addition to UG's suggestions you can also use instr() with the tag.
for instance a tag like - Req NL AA
Code:
If InStr(1, ctl.Tag, "Req") Then ...

If InStr(1, ctl.Tag, "AA") Then ...
 
@Tupacmoche
Just reinforcing the idea of how useful the tag property is for controlling the state of a group of controls, have a look at my example database here https://www.access-programmers.co.uk/forums/showthread.php?t=293439

Unlike Tony, I chose to use code in a standard module so you have a choice of methods.

@Moke
I'd never thought of using ctl.Tag in an Instr expression. Thanks. That could be useful
 
let's say you were already using Tag property for something else

Christ! It only seems like 5 minutes ago that I created The "Nifty Container" which is another way of identifying a group of controls.

The "Nifty Container" allows you to avoid using the Control(s) Tag Property, and may be handy for programmers that use the Control Tag Property for something else.

The "Nifty Container":-


offers a visual way of setting up groups of controls. There is also the possibility of a "Venn Diagram" arrangement of Controls. You could have some controls just in one container, some in another, and some in the overlap. I have no idea what the "Venn Diagram" arrangement could be used for, but it's definitely interesting, and I'm sure someone will think of something!

Nifty Container - Nifty Access​

 
Last edited:

Users who are viewing this thread

Back
Top Bottom