When Clickbox is checked-automatically enter text into another field (1 Viewer)

mkdrep

Registered User.
Local time
Today, 18:56
Joined
Feb 6, 2014
Messages
176
See attached (.jpg)
I would like to have one field filled in with a specific text depending on which checkbox is clicked.
In the attached example, I would like the [Which Mfg] field, filled in automatically with "Special-Lite" when the [Spec-Lite] checkbox is checked.

If the [Select] checkbox is checked, the [Which Mfg] field would be automatically filled with the text "Select"

Any guidance on how to achieve this would be greatly appreciated. Thank you.
 

Attachments

  • 1-Checkbox-Fill-In_Field.jpg
    1-Checkbox-Fill-In_Field.jpg
    50 KB · Views: 43

theDBguy

I’m here to help
Staff member
Local time
Today, 15:56
Joined
Oct 29, 2018
Messages
21,453
Hi,

To affect another control when one is updated, you can use the AfterUpdate event of the control being updated by the user (your checkboxes). However, just looking at your image doesn’t guve me enough information to tell specifically how to do it. For example, are the checkboxes exclusive from each other? Or can the user select more than one? I see you have a combobox too. What is its Row Source? Is it bound to a numeric field?
 

mkdrep

Registered User.
Local time
Today, 18:56
Joined
Feb 6, 2014
Messages
176
I have written the following code which accomplishes what I want.

Code:
Private Sub JP_Special_Lite_Click()
    If Me.JP_Special_Lite = True Then
        Me.JPMfgOnCall.Value = "Special-Lite"
    Else
        Me.JPMfgOnCall.Value = Null
    End If

End Sub

When JP_Special_Lite is Clicked, the value "Special-Lite" is entered into JPMfgOnCall field.

There are (5) possible click boxes to choose from. Any suggestions as to the code I would have to write to only allow one click box to be chosen?

Thanks
 
Last edited by a moderator:

Gasman

Enthusiastic Amateur
Local time
Today, 23:56
Joined
Sep 21, 2011
Messages
14,231
Change the control to a radio button group?
That is what that type of control is for.?

Else disable the other buttons in each checkbox click event.?
 

Micron

AWF VIP
Local time
Today, 18:56
Joined
Oct 20, 2018
Messages
3,478
OK, dumb question? Why not just use a combo with 2 (or is it 5) items in a list? Then there shouldn't be a need to vba a value into some other control based on a check selection.
 
Last edited:

mkdrep

Registered User.
Local time
Today, 18:56
Joined
Feb 6, 2014
Messages
176
Actually, not a dumb question at all, Micron! That is the way I have things currently set up. Both the click box and the text field are used for different reasons. Rather than have to do two things, I am just trying to ensure that once the click box is checked, the text field is automatically filled. Trying to depend on the user to do both has proved problematic in the past.
 

mkdrep

Registered User.
Local time
Today, 18:56
Joined
Feb 6, 2014
Messages
176
Gasman:
I will give your suggestion a try and let you know how it works.
thx!
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:56
Joined
Sep 21, 2011
Messages
14,231
Always :D

However unless the user needs to see that text, you could still do whatever you need to do 'behind the scenes'?

Trying to depend on the user to do both has proved problematic in the past.
 

mkdrep

Registered User.
Local time
Today, 18:56
Joined
Feb 6, 2014
Messages
176
Gasman: I could do that "behind the scenes and might in the future. However, the users are currently trained to do both at this time...want to keep changes simple at this point in time.... lol
 

Micron

AWF VIP
Local time
Today, 18:56
Joined
Oct 20, 2018
Messages
3,478
You can design it in such a way of course, but it doesn't seem like a sound approach. For me, the test is always based on "if I need another value later, will I have to add another object/field?". If the answer is yes, quite certain that it isn't efficiently designed, which is what I think your answer would be.
It sounds like the problem you referred to is because you aren't forcing the user to choose a combo item when they are supposed to, which is a form of validation - a common topic. In the case of a combo needing another item, it ought to be just a new record being added to a table at best, or its value list at worst but definitely not a new object or field. You would not only need 2 more controls (box or button and label) plus will have to modify your code to accommodate the additional option. Maybe you will never have to do so for this form, but I still think it doesn't pass that test.

I do agree that the option group is probably better than a bunch of checkboxes.
 

mkdrep

Registered User.
Local time
Today, 18:56
Joined
Feb 6, 2014
Messages
176
Food for thought, Micron.
I will re-evaluate my approach because what you are telling me makes a lot of sense.

thank you
 

Micron

AWF VIP
Local time
Today, 18:56
Joined
Oct 20, 2018
Messages
3,478
You're welcome, and good luck with your project!
 

Users who are viewing this thread

Top Bottom