compare fields in listbox

  • Thread starter Thread starter deb
  • Start date Start date
D

deb

access 2003

On form f018ContrPerf I have a combobox called "UnitNo" and a listbox called
"lstUnitType" (multiselect=none), unbound and the primary key of the
listbox's record is UnitType (text) .

User selects a specific unit or can select "All Units" from the "UnitNo"
combobox. When the selection is made the listbox "lstUnitType" is populated
with the specific UnitType or a list of all UnitTypes if the selection was
"All Units".

If "all units" selected then I need to know if all the UnitTypes in the
listbox "lstUnitType" fieldname "UnitType" are alike.

If they are alike then
Me.f018ContrPerfDetails.Form.optHP.Visible = True
else
Me.f018ContrPerfDetails.Form.optHP.Visible = false

Some of the options in the listbox "lstUnitType" may be something like...
ST
ST
ST
or it could be
ST
BFTG
and so on
so if the list box displays:
ST
ST
ST
Then Me.f018ContrPerfDetails.Form.optHP.Visible = True
else
Me.f018ContrPerfDetails.Form.optHP.Visible = false
 
deb said:
access 2003

On form f018ContrPerf I have a combobox called "UnitNo" and a listbox
called
"lstUnitType" (multiselect=none), unbound and the primary key of the
listbox's record is UnitType (text) .

User selects a specific unit or can select "All Units" from the "UnitNo"
combobox. When the selection is made the listbox "lstUnitType" is
populated
with the specific UnitType or a list of all UnitTypes if the selection was
"All Units".

If "all units" selected then I need to know if all the UnitTypes in the
listbox "lstUnitType" fieldname "UnitType" are alike.

If they are alike then
Me.f018ContrPerfDetails.Form.optHP.Visible = True
else
Me.f018ContrPerfDetails.Form.optHP.Visible = false

Some of the options in the listbox "lstUnitType" may be something like...
ST
ST
ST
or it could be
ST
BFTG
and so on
so if the list box displays:
ST
ST
ST
Then Me.f018ContrPerfDetails.Form.optHP.Visible = True
else
Me.f018ContrPerfDetails.Form.optHP.Visible = false


How many columns does the list box have? Of those, which column contains
the field that you want to compare for "likeness"?
 
Listbox has 5 fields and the first one is the one to use for comparison.
it is named UnitType. (text value)

Thank you!!!
 
deb said:
Listbox has 5 fields and the first one is the one to use for comparison.
it is named UnitType. (text value)


The names of the fields in a list box's rowsource are irrelevant -- when
you're working with the list box, all you have are rows, columns, and
ItemData.

I assume that the bound column is some other column; otherwise, Access
would not be able to distinguish among the rows in the list box.

This code should tell you if all rows in the list box have the same value
for the first column:

'------ start of code ------
' WARNING: AIR CODE

Dim i As Long
Dim blnSameType As Boolean
Dim strUnitType As String

blnSameType = True

With lstUnitType
i = Abs(.ColumnHeads)
If .ListCount > i Then
strUnitType = .Column(0, i)
While i < (.ListCount - 1) And blnSameType
i = i + 1
If .Column(0, i) & "" <> strUnitType Then
blnSameType = False
End If
Wend
End If
End With

Me.f018ContrPerfDetails.Form.optHP.Visible = blnSameType
'------ end of code ------
 
Back
Top