COMMA PROBLEM IN REMOVEITEM

  • Thread starter bifteki via AccessMonster.com
  • Start date
B

bifteki via AccessMonster.com

I have a form connected to a database in SQL Server.
In this form I have a list which is filled in with items the user chooses
from a combobox. These items are fields from the database but because of the
way it's being populated I have made it a Value List.

I have added coded to the double click event of the list, through which the
user removes the selected item from the list. Following is the code:

Private Sub lst_selected_products_DblClick(Cancel As Integer)
Dim selIndex As Integer

If (Not IsNull(lst_selected_products.ListIndex)) Then
If ((lst_selected_products.ListIndex > 0) Or (lst_selected_products.
ListIndex = 0)) Then
selIndex = lst_selected_products.ListIndex
lst_selected_products.RemoveItem (selIndex)
End If
End If
End Sub

Generally it runs OK, but the problem occurs when the item I want to remove
has a comma in its value. The list has 3 columns and for some reason the
comma isn't escaped by Access and considered a delimiter instead. So I end up
with some mixed-up data in my columns.
This is not a problem in Access 2007, as it works fine. I guess it's a bug of
the 2003 version. Does anyone know any solution to this?
 
D

Dirk Goldgar

bifteki via AccessMonster.com said:
I have a form connected to a database in SQL Server.
In this form I have a list which is filled in with items the user chooses
from a combobox. These items are fields from the database but because of
the
way it's being populated I have made it a Value List.

I have added coded to the double click event of the list, through which
the
user removes the selected item from the list. Following is the code:

Private Sub lst_selected_products_DblClick(Cancel As Integer)
Dim selIndex As Integer

If (Not IsNull(lst_selected_products.ListIndex)) Then
If ((lst_selected_products.ListIndex > 0) Or (lst_selected_products.
ListIndex = 0)) Then
selIndex = lst_selected_products.ListIndex
lst_selected_products.RemoveItem (selIndex)
End If
End If
End Sub

Generally it runs OK, but the problem occurs when the item I want to
remove
has a comma in its value. The list has 3 columns and for some reason the
comma isn't escaped by Access and considered a delimiter instead. So I end
up
with some mixed-up data in my columns.
This is not a problem in Access 2007, as it works fine. I guess it's a bug
of
the 2003 version. Does anyone know any solution to this?


I;ve tried to reproduce your problem, so far with no success. Are you sure
you're setting the rowsource values correctly when you first fill the list?
What is your code to do that? What is the actual value of the control's
RowSource property before you attempt to remove the item?

Incidentally, but unrelated to your problem, I don't think this test:
If (Not IsNull(lst_selected_products.ListIndex)) Then

.... is necessary, as I don't believe the ListIndex property can ever be
Null.

And this test:
If ((lst_selected_products.ListIndex > 0) Or
(lst_selected_products.ListIndex = 0)) Then

.... could simply be:

If lst_selected_products.ListIndex >= 0 Then

.... couldn't it?
 
B

bifteki via AccessMonster.com

You are right about your last remark - no specific reason why I wrote it this
way. Concerning the (Not IsNull) test I just put it there because I'm not
very familiar with the ListIndex property, just in case...

I'm certain this problem exists as I have one PC with Access 2003 and another
with 2007 so I've tested it many times in both. In Access 2007 it runs
perfectly but in 2003 this problem occurs ONLY in cases of one of the columns
having a comma in its string.

Anyway, I agreed with the user to have Office 2007 installed on her PC.
However if anyone has a solution to offer it's welcome -mostly out of
curiousity.

Dirk said:
I have a form connected to a database in SQL Server.
In this form I have a list which is filled in with items the user chooses
[quoted text clipped - 27 lines]
of
the 2003 version. Does anyone know any solution to this?

I;ve tried to reproduce your problem, so far with no success. Are you sure
you're setting the rowsource values correctly when you first fill the list?
What is your code to do that? What is the actual value of the control's
RowSource property before you attempt to remove the item?

Incidentally, but unrelated to your problem, I don't think this test:
If (Not IsNull(lst_selected_products.ListIndex)) Then

... is necessary, as I don't believe the ListIndex property can ever be
Null.

And this test:
If ((lst_selected_products.ListIndex > 0) Or
(lst_selected_products.ListIndex = 0)) Then

... could simply be:

If lst_selected_products.ListIndex >= 0 Then

... couldn't it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top