how to hide some of the fields in the listbox

T

thread

Hi all
i built a module and i need to filter some of the items appears in the
list from a table
so only few on the fields will appear
in the Row Source Type appear "Field List" and in the Raw Source
appear the name of the table
what should change in order the decide exactly on the items appear in
the list?
any ideas?
 
G

ghetto_banjo

You can either set column widths = 0 for the fields that you do not
want to show in the listbox (format tab of properties for listbox)

Or you can create a query on that table that has only the fields you
want to show and use that query as your rowsource.
 
T

thread

hi
thank you very much for the quick replay
the column idea is very good the issue is that i dont have several
column,i have just one column consist of all the table field's name
 
T

thread

Use the form's column widths property for each width in inches, separatedby
semicolons.  If you have 3 columns and want the 1st hidden, the 2nd 0.5
inches, and the 3rd 1 inch wide, it would look like this:

0";0.5";1.0"

Chris

is it posible to play with the size of the item names?
 
J

Jack Cannon

It appears that a possible confusion factor may be involved here. You
stated, "so only few on the fields will appear". You also said that there is
only one column. That tends to convey the impression that you do not really
want to restrict the fields but instead want to restrict the rows displayed
in the list box. If that is the case you probably need to use a query
instead of a table in the list box and restrict the rows through the WHERE
clause of the query.

Jack Cannon
 
J

John Spencer

You can't limit the fields that appear when you use Field List as the
row source type if you use a table as the row source. If you use a
query as the row source you can limit the fields that appear by limiting
the fields in the query's SELECT clause (the fields you display).

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
K

ken

The only way I can think of to limit the list to specific field names
would be to use some sort of naming convention for the fields whose
names you want to appear in the list. If you ended each field name
with a tilde character ~ for instance to indicate that it is to be
included in the list then you can fill the list box with code like
this in the form's open event procedure:

Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim ctrl As Control
Dim strField As String

Set ctrl = Me.YourListBox

Set dbs = CurrentDb
Set tdf = dbs.TableDefs("YourTableName")

ctrl.RowSourceType = "Value List"

For Each fld In tdf.Fields
strField = fld.Name
If Right(strField, 1) = "~" Then
ctrl.AddItem Left(strField, Len(strField) - 1)
End If
Next fld

This would list the field names without the tilde in each case. You'd
have to remember to include the tilde when referencing the field in
code, queries etc of course.

While it will work I don't like this as a solution, however. If you
really need to do this then a better solution, which doesn't involve
messing up the column names, would be have a table, TableStructures
say, with three columns TableName, FieldName and ShowInList, the last
being a Boolean (Yes/No) column. Its primary key would be a composite
one of the TableName and FieldName columns. You can then edit the
table, setting the ShowInList column to True for those to be listed,
and use a query as the RowSource property of the list box:

SELECT FieldName
FROM TableStructures
WHERE TableName = "YourTableName"
AND ShowInList
ORDER BY FieldName;

It would be possible to fill the TableStructures table with all table
and field names from your database automatically with some VBA code
which loops through the Tabledefs collection, then through the Fields
collection of each Tabledef object, inserting a row into the
TableStructures table for each, leaving you to then edit the
ShowInList column manually.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top