Results 1 to 2 of 2
  1. #1
    dshillington is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2011
    Posts
    7

    Insert Multiple Checkbox Values to one Textbox

    First of all I want to thank everyone on this forum for their knowledge and expertise in VBA, it has been an invaluable tool in assisting me with any questions I might have had. But now I’m really stumped, and my hours of googling have resulted in no answers.



    I have a form with 20 bound checkboxes on it. These checkboxes, when checked, insert different people to cc my form’s contents to. This function works as its intended (thank you pbaldy).

    My current problem is that when each box is checked, I want to display in the body of my auto-generated email a value (the checkbox name) associated with each checked box. What I have tried to do is create an unbound text box on my form that auto-populates with the checkbox name (value) each time a checkbox is checked. However, I need this textbox to auto-update if a checkbox is unchecked in case someone accidentally checks it. This is not happening and my frustration is growing…….from there I will reference this text box for the body of my email.

    I am using the following code for each checkbox and can’t seem to figure this out…….

    Private Sub Checkbox1_Click()
    Dim strcomment As String
    strcomment = Me.Checkbox1
    If Me.Checkbox1 = "-1" Then
    Me.Text187 = "MAA" & vbCrLf & strcomment & Me.Text187
    End If

    End Sub

    Private Sub Checkbox1_AfterUpdate()
    Dim strcomment As String
    strcomment = Me.Checkbox1
    If Me.Checkbox1 = "0" Then
    Me.Text187 = "" & vbCrLf & strcomment & Me.Text187
    End If
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, you want to test for -1 and 0 not "-1" and "0" (drop the quotes). Secondly, I would simply use the after update event of the checkbox and use an Else clause to handle the False. Finally, the task at hand can be easy or tricky, depending on what you're adding. Given your example, it would be fairly easy. This should delete "MAA" from the textbox:

    Code:
    If (Me.Checkbox1) Then
      Me.Text187 = "MAA" & vbCrLf & strcomment & Me.Text187
    Else
      Me.Text187 = Replace(Me.Text187, "MAA", "")
    End If
    That said, it would also take out any other instances of "MAA" that might appear in the textbox, so it could get problematic. I would probably not try to build this string until the user was done making their selections. That way you don't have to worry about undoing anything.
    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: 3
    Last Post: 12-06-2011, 07:37 AM
  2. Replies: 0
    Last Post: 03-08-2011, 05:56 PM
  3. Not sure why textbox not working for some values
    By jtkjames in forum Programming
    Replies: 1
    Last Post: 07-21-2010, 04:26 AM
  4. Replies: 1
    Last Post: 03-25-2009, 02:20 PM
  5. Combining textbox and checkbox data
    By jgarner in forum Access
    Replies: 0
    Last Post: 12-11-2008, 11:10 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