Sorry about the amount of code!!
lstfield is the first listbox
mylist is the field being populated
lsttab is another listbox whose selections are called upon
CkFldAll and CkTabAll are just tick boxes (they would normally be set to false)
Hope you can help,
Cheers...
Private Sub LstField_Click()
DoCmd.Hourglass True
If CkFldAll = False Then LstFldFunc
DoCmd.Hourglass False
End Sub
Sub LstFldFunc()
Dim varItm As Variant
Dim strfld As String
Dim StrTab As String
On Error GoTo ErrorDo
MyList.Enabled = True
Info1.Caption = "No Item Selected"
Info1.ForeColor = RGB(0, 0, 0)
Info2.Caption = "No Item Selected"
Info2.ForeColor = RGB(0, 0, 0)
Info5.Caption = "No Item Selected"
Info5.ForeColor = RGB(0, 0, 0)
If obRecordset.State = 1 Then obRecordset.Close
MyList.RowSource = "BlankImport"
strfld = "''"
For Each varItm In LstField.ItemsSelected
strfld = strfld & ", '" & LstField.Column(0, varItm) & "'"
Next varItm
If strfld = "''" Then
MyList.Enabled = False
GoTo NotError
End If
GeneralSub
GoTo NotError
ErrorDo:
MsgBox "An Error Has Occurred", vbCritical, "Warning"
DoCmd.Hourglass False
NotError:
End Sub
Sub GeneralSub()
Dim strfld As String
Dim StrTab As String
Set connection = New ADODB.connection
connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & CurrentDb.Name & ";"
If CkFldAll = False Then
strfld = "''"
For Each varItm In LstField.ItemsSelected
strfld = strfld & ", '" & LstField.Column(0, varItm) & "' "
Next varItm
Else
strfld = "All"
End If
If CkTabAll = False Then
StrTab = "''"
For Each varItm In LstTab.ItemsSelected
StrTab = StrTab & ", '" & LstTab.Column(0, varItm) & "' "
Next varItm
Else
StrTab = "All"
End If
If StrTab = "All" Then
If strfld = "All" Then
If SumVar = "X" Then
obRecordset.Open "SELECT * from audit" & Suffix, connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
Else
obRecordset.Open "SELECT * from audit" & Suffix & " " & SumVar2, connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
End If
Else
If SumVar = "X" Then
obRecordset.Open "SELECT * from audit" & Suffix & " where audit" & Suffix & ".name in(" & strfld & "

", connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
Else
obRecordset.Open "SELECT * from audit" & Suffix & " where audit" & Suffix & ".name in(" & strfld & "

" & SumVar, connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
End If
End If
Else
If strfld = "All" Then
If SumVar = "X" Then
obRecordset.Open "SELECT * from audit" & Suffix & " where audit" & Suffix & ".table in(" & StrTab & "

", connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
Else
obRecordset.Open "SELECT * from audit" & Suffix & " where audit" & Suffix & ".table in(" & StrTab & "

" & SumVar, connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
End If
Else
If SumVar = "X" Then
obRecordset.Open "SELECT * from audit" & Suffix & " where audit" & Suffix & ".table in(" & StrTab & "

and audit" & Suffix & ".name in(" & strfld & "

", connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
Else
obRecordset.Open "SELECT * from audit" & Suffix & " where audit" & Suffix & ".table in(" & StrTab & "

and audit" & Suffix & ".name in(" & strfld & "

" & SumVar, connection, adOpenForwardOnly, adLockReadOnly
FillMyList
obRecordset.Close
MyList.RowSourceType = "SasImport"
End If
End If
End If
For Each varItm In MyList.ItemsSelected
StrTst = MyList.Column(0, varItm)
Info1.Caption = MyList.Column(0, varItm)
Info1.ForeColor = RGB(200, 0, 0)
Info2.Caption = MyList.Column(1, varItm)
Info2.ForeColor = RGB(200, 0, 0)
Info5.Caption = MyList.Column(4, RSPos)
Info5.ForeColor = RGB(200, 0, 0)
Next varItm
If StrTst = Empty Then
Info1.Caption = "No Item Selected"
Info1.ForeColor = RGB(0, 0, 0)
Info2.Caption = "No Item Selected"
Info2.ForeColor = RGB(0, 0, 0)
Info5.Caption = "No Item Selected"
Info5.ForeColor = RGB(0, 0, 0)
End If
connection.Close
End Sub
Function SasImport(fld As Control, id As Variant, row As Variant, col As Variant, code As Variant) As Variant
Dim test As String
Select Case code
Case acLBInitialize
SasImport = True
Case acLBOpen
SasImport = 1
Case acLBGetRowCount
SasImport = RsCnt
Case acLBGetColumnCount
SasImport = 9
Case acLBGetColumnWidth
Select Case col
Case 0
SasImport = 0
Case 1
SasImport = 0
Case 2
SasImport = "6cm"
Case 3
SasImport = "3cm"
Case 4
SasImport = 0
Case 5
SasImport = "3cm"
Case Else
SasImport = 0
End Select
Case acLBGetValue
On Error GoTo ErrorPart
Select Case col
Case 0
SasImport = MyList1(row)
Case 1
SasImport = MyList2(row)
Case 2
SasImport = MyList3(row)
Case 3
SasImport = MyList4(row)
Case 4
SasImport = MyList5(row)
Case 5
SasImport = Format(MyList6(row), "0.00%"

End Select
GoTo NextPart
ErrorPart:
SasImport = ""
NextPart:
RSPos = row
End Select
End Function