Add Quotes to Code

joeserrone

The cat of the cul-de-sac
Local time
Today, 01:25
Joined
Dec 17, 2006
Messages
164
Hello everyone I have the following code listed below. I need to be able to have a " and the beginning and ending of every item is selected in a muti-select listbox. so for example if a user selects Balance and Capture in the list box. This code right now populates a text box I am using for a query criteria with: Balance or Capture
How can I get it to produce "Balance" or "Capture"


Dim lngLoop As Long
Dim strIDs As String

If ListCategoryEdit.ItemsSelected.Count > 0 Then
strIDs = ""
For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
strIDs = strIDs & "" & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & " OR "

Next lngLoop
strIDs = Left(strIDs, Len(strIDs) - 4)
txtQueryCriteria = strIDs
DoCmd.OpenQuery "EditQuery"
Else
txtQueryCriteria = ""
MsgBox "No names are selected!", vbExclamation
End If
 
Hello everyone I have the following code listed below. I need to be able to have a " and the beginning and ending of every item is selected in a muti-select listbox. so for example if a user selects Balance and Capture in the list box. This code right now populates a text box I am using for a query criteria with: Balance or Capture
How can I get it to produce "Balance" or "Capture"


Dim lngLoop As Long
Dim strIDs As String

If ListCategoryEdit.ItemsSelected.Count > 0 Then
strIDs = ""
For lngLoop = 0 To ListCategoryEdit.ItemsSelected.Count - 1
strIDs = strIDs & "" & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & " OR "

Next lngLoop
strIDs = Left(strIDs, Len(strIDs) - 4)
txtQueryCriteria = strIDs
DoCmd.OpenQuery "EditQuery"
Else
txtQueryCriteria = ""
MsgBox "No names are selected!", vbExclamation
End If

When using VB, the character " can be expressed as chr(34). Check out the chr() function. You may find other uses for it as well.
 
I appreciate all your help on this, I understand it much better now. I added
strQuote = Chr$(34)
strIDs = strIDs & strQuote & ListCategoryEdit.ItemData(ListCategoryEdit.ItemsSelected(lngLoop)) & strQuote & " OR "

and worked exactly like I needed to!

Thanks again
 

Users who are viewing this thread

Back
Top Bottom