Private Sub GoGoNamesComboBox(WhichName As String)
'MsgBox ("GoGoNamesComboBox begins")
Dim stringSELECT As String
Dim stringWHEREfirst As String
Dim stringWHEREsecond As String
Dim stringORDERBY As String
stringWHEREsecond = ""
stringSELECT = "SELECT [App Info].[Soc Sec #] as [Soc Sec], [Last Name] & ', ' & [First Name] & ' ' & [MA] AS Name FROM [App Info]"
Select Case WhichName
Case "All"
stringWHEREfirst = ""
If Me.ShowCanceledTerminated = False Then 'ShowCanceledTerminated is a checkbox on the form
stringWHEREsecond = " WHERE [App Info].[App Type] <> 'Canceled/Terminated'"
End If
Case "AB"
stringWHEREfirst = " WHERE ([App Info].[Last Name] aLike '[AB]%')"
If Me.ShowCanceledTerminated = False Then 'ShowCanceledTerminated is a checkbox on the form
stringWHEREsecond = " AND [App Info].[App Type] <> 'Canceled/Terminated'"
End If
'...
End Select
stringORDERBY = " ORDER BY CharacterReplacer(Nz([App Info].[Last Name]), ' ', '-', ''''), CharacterReplacer(Nz([App Info].[First Name]), ' ', '-', '''');"
'stringORDERBY = " ORDER BY REPLACE(Nz([App Info].[Last Name]),' ',''), REPLACE(Nz([App Info].[First Name]),' ',''), REPLACE(Nz([App Info].MA),' ','');"
Me.Names_Combo_Box.RowSource = stringSELECT & stringWHEREfirst & stringWHEREsecond & stringORDERBY
'Now that I've changed the RowSource, reload the thing
Me.Names_Combo_Box.SetFocus
Me.Names_Combo_Box.Requery
'...
Me.Names_Combo_Box.Dropdown
'MsgBox ("GoGoNamesComboBox ends")
End Sub
Function CharacterReplacer(aString As String, ParamArray characterList() As Variant) As String
Dim upperBound As Integer
Dim counter As Integer
Dim Location As Integer
upperBound = UBound(characterList)
For counter = 0 To upperBound
Location = InStr(aString, characterList(counter))
If Location > 0 Then
Dim leftSide As String
Dim rightSide As String
leftSide = Left(aString, Location - 1)
rightSide = Mid(aString, Location + 1)
CharacterReplacer = leftSide + rightSide
Else
CharacterReplacer = aString
End If
Next counter
End Function