Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call code to refer to a List Box or a Combo Box 1

Status
Not open for further replies.

DevelopV

Technical User
Mar 16, 2012
113
ZA
I have the following extract of code
Code:
Public Sub SortColumn(ctlList As Listbox, strField As String, strOrder As String, Optional strForceSortOrder As String)
    
Dim strSQL As String
Dim strSorted As String
Dim intInString As Long
Dim strSortOrder As String
dim strSQL as String
 
intInString = InStr(1, ctlList.RowSource, "Order By")

strSQL = ""
If intInString > 0 Then
    strSQL = Left(ctlList.RowSource, intInString - 1)
    Else
    strSQL = ctlList.RowSource
End If

ctlList.RowSource = strSorted
ctlList.Requery
 
End Sub

I would like to use the code for combo box's as well. I could simply create a new sub in which I replace "ctlList As Listbox" with "ctlCombo As ComboBox", but this does not make sense. How can I modify the code so that I can call it from either a list box or a combo box?
I currently call the sub like this
Code:
SortColumn Me.lstCustomer, "Area", Me.cmdSortArea.Caption, ""
Thanks in advance
 
I'd use this:
ctlList As Access.Control

Then in your code test its ControlType property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I already showed you how to do this in your previous post about passing a listbox to a procedure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top