Results 1 to 10 of 10
  1. #1
    raf1435flight is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2019
    Posts
    5

    Auto populate textbox based on checkbox value

    Greetings,


    I am new to this forum and I thank you very much for allowing me the opportunity to ask questions. I have a form where I'd like to be able to click a checkbox and the following text box auto populates with a predetermined text. If the checkbox isn't checked, then the text box stays blank. The checkbox is named PRORule1slct and the textbox is PRORule1. This form is for a Probation Violation Affidavit and the text box lists a rule of supervision Their are 14 Rules in all and I have a checkbox and text box for each.
    Would I list the text of each rule in the default value property of the table that the form is bound to?
    I really appreciate the help. I have never had any formal training w/ MS ACCESS and am not really proficient in VBA.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Code:
    sub chkBox_afterupdate()
    if chkBox.value then
       txtbox = "Bob"
    else
    
    txtbox = ""
    endif end sub
    note: using checkboxes requires programming. Instead consider using values. A table of all 14 rules as text.
    these could be added to the Person's sub-table
    personID, Violation, Date
    123, Jaywalking, 1/1/19
    123, Whistling, 2/18/19

    these can be added /removed from the table as rules change. Checkboxes must be programmed.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    The checkbox is named PRORule1slct and the textbox is PRORule1. This form is for a Probation Violation Affidavit and the text box lists a rule of supervision Their are 14 Rules in all and I have a checkbox and text box for each.
    If each of the textboxes are bound to a field in the forms record source then I would suggest that your database may not be properly normalized. That is usually the case when table fields and form controls are named with sequential numbers. e.g. PRORule1, PRORule2, PRORule3 etc
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    Before making suggestions I suspect you have a poorly designed table - you have 14 rules at the moment. What if in the future there is a 15th or 16th? or some rules are dropped. Or modified? It looks like if any of these changes occur you are going to need to modify the table, forms, reports and code. With regards a rule being modified - would a modification also apply to all all existing records? or just new ones?

    Please clarify how you would handle each of these scenarios with your current setup.

    This may seem like it is nothing to do with your question but it does have a big impact on what can be provided as an answer

  5. #5
    raf1435flight is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2019
    Posts
    5

    That was QUICK!!!!

    Quote Originally Posted by ranman256 View Post
    Code:
    sub chkBox_afterupdate()
    if chkBox.value then
       txtbox = "Bob"
    else
    
    txtbox = ""
    endif end sub
    note: using checkboxes requires programming. Instead consider using values. A table of all 14 rules as text.
    these could be added to the Person's sub-table
    personID, Violation, Date
    123, Jaywalking, 1/1/19
    123, Whistling, 2/18/19

    these can be added /removed from the table as rules change. Checkboxes must be programmed.
    Big thank you's to you folks for getting back w/ me so quickly. I've been able to google things here and there and piece things together, but was always afraid to reach out for help. Thanks again.
    Since I am but a novice, I am sure my DB is not normalized. (not sure what that means) and my tables are probably poorly designed. As far as adding additional rules, they are set in stone.

    Ranman (Running Man- awesome movie- Hunger Games is a ripoff of it) If I get what you are saying, I should make a table w/ the rules in it and join it to the original attributes table. (which I have done)

    As far as your VBA goes, is "Bob" the name of the text box or the actual rule that I have listed as the default value in said box? I assume that each checkbox will have to have code written for it as well.
    Thanks again for all of your help.

  6. #6
    raf1435flight is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2019
    Posts
    5
    Hello again,
    I am having some trouble getting this thing to work. Let me explain with a bit more detail as to what I am trying to accomplish:

    I have a text box named "Rule1". It's default value is "Rule 1: I will obey the laws of the United States....." I have a checkbox next to it named Rule1cb. What I'm trying to do is when the checkbox is clicked, the aforementioned text automatically populates in the textbox.
    I tried the code that was listed earlier and couldn't get it to work. Obviously, I'm doing something wrong. As always, any help is greatly appreciated. Thanks.

    Originally Posted by ranman256
    Code:
    sub chkBox_afterupdate()
    if chkBox.value then
    txtbox = "Bob"
    else
    txtbox = ""
    endif
    end sub
    note: using checkboxes requires programming. Instead consider using values. A table of all 14 rules as text.
    these could be added to the Person's sub-table
    personID, Violation, Date
    123, Jaywalking, 1/1/19
    123, Whistling, 2/18/19

    these can be added /removed from the table as rules change. Checkboxes must be programmed.

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Looks like nobody's around. Ranman's code looks fine to me; did you change the names of the combo and textbox to yours? What exactly does "couldn't get it to work" mean?

    I agree with the suggestion to have these in a table. I've got a table with generic reasons for holding a vehicle and a combo on a form. If the user chooses a generic reason from the combo, it populates a textbox:

    Me.txtShopComments = Me.cboHoldReason
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    raf1435flight is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2019
    Posts
    5
    Quote Originally Posted by pbaldy View Post
    Looks like nobody's around. Ranman's code looks fine to me; did you change the names of the combo and textbox to yours? What exactly does "couldn't get it to work" mean?

    I agree with the suggestion to have these in a table. I've got a table with generic reasons for holding a vehicle and a combo on a form. If the user chooses a generic reason from the combo, it populates a textbox:

    Me.txtShopComments = Me.cboHoldReason
    Hello Pbaldy,
    What I mean by can't get it to work is that I entered the code and when I check the checkbox, nothing happens. I changed the names in the code. Sorry, I am very new to VBA and have absolutely no training. Access is awesome, but very complicated (to the non-IT trained user)

  9. #9
    raf1435flight is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Oct 2019
    Posts
    5
    Here's what I plugged into the code:
    Sub Rule1cb_afterupdate()
    If Rule1cb.Value = "Yes" Then
    Rule1 = "Rule 1: I will obey the laws of the United States, or any State in which I may be, as well as any municipal ordinances."
    Else
    txtbox = ""
    End If
    End Sub

    The checkbox is set to Yes/No with default value of "No".

  10. #10
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You didn't use ranman's test. A checkbox doesn't return a text value. Either use the test provided or:

    If Rule1cb.Value Then
    If Rule1cb.Value = Yes Then
    If Rule1cb.Value = True Then
    If Rule1cb.Value = -1 Then

    all of which should be functionally identical. I'd point out that you're referring to two different objects:

    Rule1 = "Rule 1: I will obey the laws of the United States, or any State in which I may be, as well as any municipal ordinances."
    txtbox = ""
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-12-2017, 12:41 AM
  2. Replies: 38
    Last Post: 05-03-2017, 09:29 AM
  3. auto populate textbox
    By willfrank in forum Access
    Replies: 1
    Last Post: 04-13-2016, 09:53 AM
  4. Replies: 7
    Last Post: 03-02-2014, 03:16 PM
  5. Auto Populate TextBox
    By Shido151 in forum Access
    Replies: 3
    Last Post: 04-23-2013, 10:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums