Hello,
I'm using a variation of support.microsoft.com/kb/135546, to build a query with custom columns. I've found a way to do it - using If statements to check the Variant's number in the list and, if it is selected, to add it on the end of a SQL string.
Here's pretty much what I'm doing at the moment:
What I'm hoping I can do, and what I need help with, if possible, is find a way to replace the separate If statements, for each varItm, with a loop that will use the current variant to determine the string to add to strSelect. Something like: intItm = intItm + 1 at the end of the loop to increment the number, and: If varItm = intItm Then to match the Variant.
What I can't get my head around, is how to use the result to then select an appropriate string. I'm assuming I'd need something like strSelect1 = "[Framework].[Reference]", strSelect2 = [Framework].[Forename], etc., and then have a piece of code after Then, to add the value of varItem to the end of strSelect to get one of the variables. Am I anywhere close?
Thanks,
Russ
I'm using a variation of support.microsoft.com/kb/135546, to build a query with custom columns. I've found a way to do it - using If statements to check the Variant's number in the list and, if it is selected, to add it on the end of a SQL string.
Here's pretty much what I'm doing at the moment:
Code:
Sub MakeQuery()
Dim ctl As Control
Dim varItm As Variant
Dim strSQL As String
Dim strSelect As String
Set ctl = Me!lstFields
For Each varItm In ctl.ItemsSelected
If varItm = 0 Then
If Len(strSelect) = 0 Then
strSelect = Chr(34) & "[Framework].[Reference]" & Chr(34)
Else
strSelect = strSelect & "," & Chr(34) & _
"[Framework].[Reference]" _
& Chr(34)
End If
If varItm = 1 Then
If Len(strSelect) = 0 Then
strSelect = Chr(34) & "[Framework].[Forename]" & Chr(34)
Else
strSelect = strSelect & "," & Chr(34) & _
"[Framework].[Forename]" _
& Chr(34)
End If
Next varItm
What I'm hoping I can do, and what I need help with, if possible, is find a way to replace the separate If statements, for each varItm, with a loop that will use the current variant to determine the string to add to strSelect. Something like: intItm = intItm + 1 at the end of the loop to increment the number, and: If varItm = intItm Then to match the Variant.
What I can't get my head around, is how to use the result to then select an appropriate string. I'm assuming I'd need something like strSelect1 = "[Framework].[Reference]", strSelect2 = [Framework].[Forename], etc., and then have a piece of code after Then, to add the value of varItem to the end of strSelect to get one of the variables. Am I anywhere close?
Thanks,
Russ