Results 1 to 13 of 13
  1. #1
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186

    Adding info into Textbox by clicking on checkbox Yes/No without deleting the previous info

    Hi everyone,

    I am writing a code to add people names into a Textbox by click on a checkbox Yes/No

    The textbox is named "Teamworktxt" and the checkboxes are "Qualitychk", "Maintenancechk", "Productionchk", "Engineeringchk"

    I want everytime when I click on the check box.. the people in charge of the department will be included into the "Teamworktxt"no matter what this textbox has already info (I dont want to delete the previous info)

    The idea is to create the list of people that will be working on the project


    My Code

    ************************************************
    Private Sub WT_Quality_Click()


    If Me.WT_Quality = -1 Then




    Dim Quality As String
    Quality = "Quality"


    Me.TeamWorktxt = DLookup("[Name]", "[Team_Work]", "[Departament]= '" & Quality & "'")


    End If

    End Sub
    **********************************************

    I have also the same code for each Checkbox but obviously when I click on one of them, it takes the info and replace it with the new one


    Does someboy have any idea to correct this?

  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
    Try

    Me.TeamWorktxt = Me.TeamWorktxt & " " & DLookup("[Name]", "[Team_Work]", "[Departament]= '" & Quality & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    By the way, I don't see the point of the variable. Why not just:

    Me.TeamWorktxt = DLookup("[Name]", "[Team_Work]", "[Departament]= 'Quality'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    You are completly right!!

    Just I was making more code than needed,

    Thank you very much!!!!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Quick question...

    I also would like to include vbCrLf to make a space by everyname into my textbox, I was doing this but is not working and it is moving to function "Else"

    **************************************************

    Private Sub WT_Quality_Click()

    If Me.WT_Quality = -1 And Me.TeamWorktxt = "" Then

    Me.TeamWorktxt = Me.TeamWorktxt & " " & DLookup("[Name]", "[Team_Work]", "[Departament]= 'Quality'"

    ElseIf Me.WT_Quality = -1 And Me.TeamWorktxt <> "" Then

    Me.TeamWorktxt = Me.TeamWorktxt & " " & DLookup("[Name]", "[Team_Work]", "[Departament]= 'Quality'"

    Else

    Me.TeamWorktxt = "Test failed"

    End If

    End Sub

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The If and ElseIf appear to do the same thing, but try:

    If Me.WT_Quality = -1 And Len(Me.TeamWorktxt & vbNullString) = 0 Then

    which checks that the textbox is empty. >0 would test for it having something in it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Wow!! Excellent they work pretty good!!!

    Just one question more...

    If I want for example to delete the name of the person added into the textbox.... how should be this code line? I'm thinking something like this...


    If Me.WT_Quality = 0 Then

    Me.TeamWorktxt =
    DLookup("[Name]", "[Team_Work]", "[Departament]= 'Quality'" 'What would be the function to take the name out?

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Put the name into a variable and then use the Replace() function, along the lines of:

    Me.TeamWorktxt = Replace(Me.TeamWorktxt, VariableName, "")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Hi!!

    Just was not so clear to me what would be this "Name" to put into this variableName

    Do I have to define a varible with DLookup and put it into?

    **********

    If Me.WT_Quality = -1 And Len(Me.TeamWorktxt & vbNullString) = 0 Then

    Me.TeamWorktxt = DLookup("[Name]", "[Work_Team]", "[Departament]= 'Quality'")

    ElseIf Me.WT_Quality = -1 And Me.TeamWorktxt <> "" Then

    Me.TeamWorktxt = Me.TeamWorktxt & " " & vbCrLf & DLookup("[Name]", "[Work_Team]", "[Departament]= 'Quality'")

    End If

    If Me.WT_Quality = 0 Then

    Me.TeamWorktxt = Replace(Me.TeamWorktxt, VariableName, "")

    End If

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The variable is just because putting the DLookup() inside the Replace() gets ungainly. Something like this. At the top you'd declare the variable:

    Dim strName As String

    then when the checkbox is unchecked:

    Code:
    If Me.WT_Quality = 0 Then
       strName = DLookup("[Name]", "[Work_Team]", "[Departament]= 'Quality'")
       Me.TeamWorktxt = Replace(Me.TeamWorktxt, strName , "")
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    charly.csh is offline Competent Performer
    Windows 8 Access 2007
    Join Date
    Nov 2014
    Posts
    186
    Woow!!

    Excellent idea!!!!
    Thank you very much!!!!!!

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo!
    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: 05-15-2019, 10:36 AM
  2. Replies: 2
    Last Post: 12-05-2014, 07:59 AM
  3. Shoiw info in second textbox
    By hendrikbez in forum Forms
    Replies: 1
    Last Post: 12-04-2014, 06:03 AM
  4. Textbox displays info but can not edit.
    By Yiannis in forum Forms
    Replies: 3
    Last Post: 11-16-2012, 01:34 PM
  5. Replies: 3
    Last Post: 10-24-2012, 05:41 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