|
-
Jul 24th, 2008, 06:22 AM
#1
Thread Starter
Member
[RESOLVED] Listbox - trailing comma for multiple records
I have the following code:
vb Code:
strSQL = strSQL & "WHERE MerchantID in ("
For f = 0 To lstMerchants.ListCount - 1
If lstMerchants.Selected(f) Then
strSQL = strSQL & (lstMerchants.ItemData(f)) & ","
End If
Next f
strSQL = strSQL & ")"
At the moment, it lists merchants in a listbox and allows the user can select as many merchants as desired. It worked well in Access and there was no probs, but when trying against a SQL database the trailing comma throws the query. If the user selects one record, then no comma, and also shouldn't be a comma on the last selected merchant. I've tried SelCount but couldn't figure out the best way to use it.
I'm sure its simple but whats the best way to counteract this problem?
Thanks in advance!
-
Jul 24th, 2008, 06:40 AM
#2
Re: Listbox - trailing comma for multiple records
This is what I use somewhere. Just always add a comma even for one selection and then get rid of it.
Code:
ilen = Len(strUpdateClause)
strUpdateClause = Mid(strUpdateClause, 1, InStrRev(strUpdateClause, ",") - 1) & " " & _
Mid(strUpdateClause, InStrRev(strUpdateClause, ",") + 1, ilen - InStrRev(strUpdateClause, ","))
-
Jul 24th, 2008, 07:15 AM
#3
Thread Starter
Member
Re: Listbox - trailing comma for multiple records
Excellent piece of code. Worked like a charm!
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|