sirhannick
Registered User.
- Local time
- Yesterday, 22:20
- Joined
- Jun 18, 2013
- Messages
- 20
Multiple Selection List - Comma Separated String - Run Query & Create Report
I've been battling this for a couple days now and I'm stumped/overwhelmed. My SQL experience isn't great. I've been doing a lot of VBA programming though. I'm using Access 2007.
So far I have a Multi Select enabled list on which the user selects the serial numbers they want. They then click the "Report" button which will trigger a query based on the selected serial numbers to create a report on those serial numbers.
I have the code for the multi-select list working already. It creates a string of comma separated values that are the serial numbers which are selected in the list. Somehow I need to pass this string to my query so it can use it as a filter. How would be the best way to use this?
I have found several links which may be pieced together for a a solution (can't post them yet)
Here is some of my code:
Also I have this routine which could be used to check to see if the serial numbers are in the list. I'm just not sure on how to patch all of this together.
Here's my current query in SQL:
(see post #4)
Then finally how to I get the query to execute and create a report based on all of this?
I may need to supply more information for someone to be able to help me, but I appreciate any and all advice. Thank you very much in advance!
I've been battling this for a couple days now and I'm stumped/overwhelmed. My SQL experience isn't great. I've been doing a lot of VBA programming though. I'm using Access 2007.
So far I have a Multi Select enabled list on which the user selects the serial numbers they want. They then click the "Report" button which will trigger a query based on the selected serial numbers to create a report on those serial numbers.
I have the code for the multi-select list working already. It creates a string of comma separated values that are the serial numbers which are selected in the list. Somehow I need to pass this string to my query so it can use it as a filter. How would be the best way to use this?
I have found several links which may be pieced together for a a solution (can't post them yet)
Here is some of my code:
Code:
Option Compare Database
Option Explicit
Private Sub Form_Current()
Dim oItem As Variant
Dim bFound As Boolean
Dim sTemp As String
Dim sValue As String
Dim sChar As String
Dim iCount As Integer
Dim iListItemsCount As Integer
iListItemsCount = 0
bFound = False
iCount = 0
For iCount = 1 To Len(sTemp) + 1
sChar = Mid(sTemp, iCount, 1)
If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
bFound = False
Do
If StrComp(Trim(EightD_List.ItemData(iListItemsCount)), Trim(sValue)) = 0 Then
EightD_List.Selected(iListItemsCount) = True
bFound = True
End If
iListItemsCount = iListItemsCount + 1
Loop Until bFound = True Or iListItemsCount = EightD_List.ListCount
sValue = ""
Else
sValue = sValue & sChar
End If
Next iCount
End Sub
Private Sub EightD_Email_Button_Click()
Dim oItem As Variant
Dim sTemp As String
Dim iCount As Integer
Dim rs As DAO.Recordset
iCount = 0
If EightD_List.ItemsSelected.Count <> 0 Then
For Each oItem In EightD_List.ItemsSelected
If iCount = 0 Then
sTemp = sTemp & EightD_List.ItemData(oItem)
iCount = iCount + 1
Else
sTemp = sTemp & "," & EightD_List.ItemData(oItem)
iCount = iCount + 1
End If
Next oItem
Else
MsgBox "Nothing was selected from the list", vbInformation
Exit Sub 'Nothing was selected
End If
MsgBox sTemp
Set rs = CurrentDb.OpenRecordset("SELECT SpeciesTB.yourFieldName1, SpeciesTB.Species FROM SpeciesTB " & _
"WHERE SpeciesTB.Species IN (" & StrCriteria & ");")
' (Do something with the resulting records)
rs.Close
End Sub
Code:
Option Compare Database
Function myInList(StringToCheck As String) As Boolean
Dim myListArray() As String
myListArray = Split(ListToCheckAgainst, ",")
For Each Item In myListArray
If ValueToCheck = Val(Item) Then
myInList = True
Exit For
End If
Next Item
End Function
(see post #4)
Then finally how to I get the query to execute and create a report based on all of this?
I may need to supply more information for someone to be able to help me, but I appreciate any and all advice. Thank you very much in advance!
Last edited: