Results 1 to 12 of 12
  1. #1
    cohnhead is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    20

    Toggle Button to Add Text to a Field

    Is there a way to have a toggle button add text to another field in a table?



    I have created a form/subform where the subform has a toggle button in triplestate. I would like to be able to make a field have three text values based on the position of the toggle button.

    Null="Not Taken"
    0="Not Mastered"
    -1="Mastered"

    Is there a way to do this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I never realized toggle button had triple state so just tested.

    Can't tell difference between Null and 0 just by viewing the button.

    I think the toggle can be bound to a number or text field and the value will be saved (I think triple state is eliminated if bound to a Yes/No field).
    Otherwise, code in Click event can set value in field: Me.fieldname = Me.toggleName.

    Suggest having a textbox bound to the same field so its content can be viewed. Set the textbox as Locked Yes and TabStop No.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cohnhead is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    20
    Quote Originally Posted by June7 View Post
    I never realized toggle button had triple state so just tested.

    Can't tell difference between Null and 0 just by viewing the button.

    I think the toggle can be bound to a number or text field and the value will be saved (I think triple state is eliminated if bound to a Yes/No field).
    Otherwise, code in Click event can set value in field: Me.fieldname = Me.toggleName.

    Suggest having a textbox bound to the same field so its content can be viewed. Set the textbox as Locked Yes and TabStop No.

    I made a text field, but when I click the toggle it either adds a "0" or a "-1" or nothing depending on the state of the toggle button (which is tied to a field called ResultPre). What I would like to do is to be able to set a text value based on the state of the button. I don't want that value to be a number. I want it to be words. I could even set up another field that automatically adds text based on the number in the ResultPre field, but I am not sure how to achieve this.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Don't bind toggle to field. Code in the toggle Click event to set value of field.

    Select Case Me.togglename
    Case -1
    Me!fieldname = "Mastered"
    Case 0
    Me!fieldname = "Not Mastered"
    Case Null
    Me!fieldname = "Not Taken"
    End Select
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    cohnhead is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    20
    Quote Originally Posted by June7 View Post
    Don't bind toggle to field. Code in the toggle Click event to set value of field.

    Select Case Me.togglename
    Case -1
    Me!fieldname = "Mastered"
    Case 0
    Me!fieldname = "Not Mastered"
    Case Null
    Me!fieldname = "Not Taken"
    End Select

    That worked. Is there a way to show the change in the form, so that I can see what the toggle selection is? I added a text box that is bound to the field, but it doesn't change when I click the toggle button. The field changes in the table, but the text box (that is bound to the changed field) only changes if I close the form and reopen it. Is there a way to reflect this change instantly on the form?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The bound textbox should immediately reflect the change. However, an alternative is to set the value by referencing the textbox.

    Me.textboxname

    I always give controls a name different from the field they are bound to, like: tbxQty
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    cohnhead is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    20
    I forgot to mention that this is a continuous form. Does this have something to do with why the text box is not updating?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The code should edit the current record. The value should show.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Consider using a combo box bound to the field in table. Have the value of the field: 1;"Not Taken";2;"Not Mastered";3;"Mastered".
    Combo box replaces toggle button and text box.

  10. #10
    cohnhead is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    20
    The reason I am using the toggle button was because I wanted to be able to do a lot of records quickly. Here is the file. Look at option 4
    Attached Files Attached Files

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Or don't use numbers in the combobox RowSource to save text:

    "Not Taken";"Not Mastered";"Mastered".

    That grey text on red is hard to read.

    Sorry, looks like need to have refresh command in the code.

    Me.Refresh

    Could have sworn that would not be needed but my memory obviously failed on this.

    Note that unbound toggle reflects the same state for all instances.

    An alternative is toggle in the subform header. Select record first then click the toggle.

    Most people expect a toggle to be an on/off choice, the third state might be confusing because there is not a third color.

    Actually, I don't see the code is recognizing Null. Change Case Null to Case Else.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    cohnhead is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2014
    Posts
    20
    Thanks June. That fixed it. I am going to try the combo box as well. I wish there was a third color for null. I was also thinking of making the toggle button transparent and setting it on top of the text field.

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

Similar Threads

  1. Toggle Button Help
    By dbalilti in forum Access
    Replies: 1
    Last Post: 07-05-2012, 04:23 AM
  2. Toggle Button Criteria
    By tylerg11 in forum Forms
    Replies: 2
    Last Post: 03-02-2012, 09:28 AM
  3. Making a toggle button hide a text box.
    By RemonKoybito in forum Forms
    Replies: 3
    Last Post: 05-20-2011, 11:34 AM
  4. Replies: 1
    Last Post: 09-13-2010, 01:57 PM
  5. Toggle Button Options
    By Matthieu in forum Forms
    Replies: 2
    Last Post: 11-23-2009, 04:05 PM

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