If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Break between ItemSelected from List Box
I have a text box that takes the entries from a multi-select list box and
concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela |
#2
|
|||
|
|||
Break between ItemSelected from List Box
Dim varRow As Variant, strText As String
strText = vbNullString If Me.lbDamagedParts.ItemsSelected.Count 0 Then For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) & ", " Next varRow Me.Text39 = "The vehicle sustained damage to the " & _ Left(strText, Len(strText) - 2) & "." Else Me.Text39 = "The vehicle did not sustain any damage." End If -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Pamela" wrote in message ... I have a text box that takes the entries from a multi-select list box and concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela |
#3
|
|||
|
|||
Break between ItemSelected from List Box
Hi Pamela,
Did you see this reply, which I just posted in the wee hours of this morning? http://www.microsoft.com/office/comm...e78&sloc=en-us (I had forgotten to come back to this group to check for replies, and the notification service is still not working, after several months, when one posts via the web as both of us have done). Tom Wickerath Microsoft Access MVP http://www.accessmvp.com/TWickerath/ __________________________________________ "Pamela" wrote: I have a text box that takes the entries from a multi-select list box and concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela |
#4
|
|||
|
|||
Break between ItemSelected from List Box
Thank you, Thank you, Thank you! I've been struggling with this aspect for 3
days and Poof! it's fixed - and working beautifully! I really appreciate your time and help in this and all of those out there that have spent time helping me on this project! Pamela "Douglas J. Steele" wrote: Dim varRow As Variant, strText As String strText = vbNullString If Me.lbDamagedParts.ItemsSelected.Count 0 Then For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) & ", " Next varRow Me.Text39 = "The vehicle sustained damage to the " & _ Left(strText, Len(strText) - 2) & "." Else Me.Text39 = "The vehicle did not sustain any damage." End If -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Pamela" wrote in message ... I have a text box that takes the entries from a multi-select list box and concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela . |
#5
|
|||
|
|||
Break between ItemSelected from List Box
Hi Doug,
I was so excited when you gave me this code and it worked just perfectly. I decided to try to make the form more user-friendly and filtered the listbox items by another cbo on the form. I thought I had it nailed today but when I tested it, all of a sudden, the items selected aren't showing up from your code here. Instead, I am getting, "The vehicle sustained damage to the , , , , ,." Any ideas why the code that worked so beautifully before would stop reading the variable just because the box is now filtered? And note, that it isn't taking the "Else" case should there be no selection, so it's reading that there is a selection and even reading the correct # of commas - but not the text itself. Thank you so very much for any help you can give me on this!! Pamela "Douglas J. Steele" wrote: Dim varRow As Variant, strText As String strText = vbNullString If Me.lbDamagedParts.ItemsSelected.Count 0 Then For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) & ", " Next varRow Me.Text39 = "The vehicle sustained damage to the " & _ Left(strText, Len(strText) - 2) & "." Else Me.Text39 = "The vehicle did not sustain any damage." End If -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Pamela" wrote in message ... I have a text box that takes the entries from a multi-select list box and concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela . |
#6
|
|||
|
|||
Break between ItemSelected from List Box
Did you change what order the fields are in the list box? Remember that the
code is supposed to be grabbing whatever's in the first column of each of the selected rows. -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Pamela" wrote in message ... Hi Doug, I was so excited when you gave me this code and it worked just perfectly. I decided to try to make the form more user-friendly and filtered the listbox items by another cbo on the form. I thought I had it nailed today but when I tested it, all of a sudden, the items selected aren't showing up from your code here. Instead, I am getting, "The vehicle sustained damage to the , , , , ,." Any ideas why the code that worked so beautifully before would stop reading the variable just because the box is now filtered? And note, that it isn't taking the "Else" case should there be no selection, so it's reading that there is a selection and even reading the correct # of commas - but not the text itself. Thank you so very much for any help you can give me on this!! Pamela "Douglas J. Steele" wrote: Dim varRow As Variant, strText As String strText = vbNullString If Me.lbDamagedParts.ItemsSelected.Count 0 Then For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) & ", " Next varRow Me.Text39 = "The vehicle sustained damage to the " & _ Left(strText, Len(strText) - 2) & "." Else Me.Text39 = "The vehicle did not sustain any damage." End If -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Pamela" wrote in message ... I have a text box that takes the entries from a multi-select list box and concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela . |
#7
|
|||
|
|||
Break between ItemSelected from List Box
When staring at your code, I remembered something I had read about the Column
function which triggered the possibility that maybe the column count had changed. I added back the ID to the list box query and it worked again. Thanks so much! "Pamela" wrote: I have a text box that takes the entries from a multi-select list box and concatenates them. My code is not reading that there is supposed to be a comma and space between each of the selected items from my list box. My code currently lists them correctly but all together but running into each other with no spaces. I believe the problem lies in line 5 where "strText" is. We tried setting it to varRow but that just lists the # of items selected. Here is my code: Dim varRow As Variant, strText As String 'strText = vbNullString For Each varRow In Me.lbDamagedParts.ItemsSelected strText = strText & Me.lbDamagedParts.Column(0, varRow) Me.Text39 = "The vehicle sustained damage to the " & strText & ", " Next varRow Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "." Thank you so much! Pamela |
Thread Tools | |
Display Modes | |
|
|