List Box default value shown

G

Guest

I have some list boxes on my form and I would like it so that when the user
runs the form there is no value in the list box window for a new record.
Right now when i create a new record the list boxes retain the last value
shown.
 
K

Ken Snell [MVP]

I assume that the listbox is unbound... so set its Row Source equal to "" in
the form's Current event if Me.NewRecord = True.
 
G

Guest

I have 18 list boxes: 4 populate the boxes with values I typed in, the other
14 are populated from tables. the values I pick will, of course, be entered
into the record.

A second question that is related is I would like the list in one of the
list boxes to be determined by the value of a previous box.

thanks for the help and the quick reply,
Damon
 
K

Ken Snell [MVP]

Are we talking of list boxes (which do not allow you to type in a value), or
a combo box (which does allow you to type in a value)?

It sounds as if you mean combo boxes. In that case, just set the .Value
property of the combo box to Null in the Current event if Me.NewRecord =
True.
 
G

Guest

These are all list boxes as I have immutable data for each one and I do not
want the ability to enter new data to exist. Click on a box, choose a value
and you are done :)

Damon
 
K

Ken Snell [MVP]

I'm a bit confused. Your original post said you didn't want any values to be
in the listbox; only way to do that is to empty the Row Source. Is that what
you want to do?

Regarding "basing one listbox on the value of another", see this article at
The ACCESS Web for an explanation of how it's done for combo boxes. It'll
work for listboxes too.
http://www.mvps.org/access/forms/frm0028.htm

--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

Let me clarify, I want values in the list boxes so that I may choose from
them, but I do not want any of the items showing up in the window upon
starting a new record. I want to be presented with a form that has no data
visible in the fields, but when I click on one of the listboxes I can select
from a choice in the list. I want the default value shown on the form to be
blank.
 
K

Ken Snell [MVP]

What "window" do you mean for the new record? I think you're referring to
some other controls on the form? Perhaps it would help if you describe your
form's setup and the actions that you are doing. I'm just not "seeing" your
setup in my mind.
 
G

Guest

OK, I have a form with some text boxes and some list boxes. The purpose of
the form is to enter the personal information of a person who is entered into
a personnel table. The text boxes are used to collect the person's name, age,
nickname, etc...; items that I cannot predict. The list boxes allow me to
choose things like rank, gender, etc.... THen I hit add record and my choices
are entered into the table. After I hit enter all the fields should display
as emtpy and in the case of the list boxes, when I click on the down arrow I
should be presented with my choices.

I hope that helps.

Damon
 
K

Ken Snell [MVP]

I think part of my confusion is because of terminologies.... a list box
doesn't have a dropdown list (shows when you click a "down" arrow) - that is
a combo box. Now I think I'm understanding what you want to do.

You want the "text box" portion of the combo box to be empty. This can be
done by setting the value of the combo box to Null.

The "trick" is to know when to do it. I assume that the combo boxes are
bound to fields in the form's Record Source table/query? When you want to
use the combo boxes, are you starting on a new record? If yes, and the combo
boxes are bound to fields, and those fields are empty, the textbox portion
of the combo box should automatically be empty.

If the combo box is not bound to a field, then you can use the form's
Current event to set the value of the combo box to Null. This could be done
only if you're starting a new record, or it can be done anytime you move
from one record to another.

Private Sub Form_Current()
'** This code assumes that the combo box is not
'** bound to a field in the form's RecordSource
' omit the If and End If lines if you want the combo box to be
' empty whenever you move from one record to another
If Me.NewRecord = True Then ' omit this line if...(see above)
Me.NameOfComboBox.Value = Null
End If ' omit this line if...(see above)
End Sub


--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

Actually, they are list boxes and they have up/down arrows in the field to
allow you to navigate through the choices. It was my mistake to say they were
dropdown lists. The rest of my concept still stands :)

Damon
 
K

Ken Snell [MVP]

Then I seem to be completely misunderstanding which controls are to be empty
when you first start. I apologize.

A list box won't have a value in a "textbox", obviously.

Are you saying the textboxes themselves should be empty? If yes, use the
same approach that I suggested for combo boxes -- set the textbox's Value
property to Null.

Are you saying that the listbox should have no "items" in its list from
which the user can select a choice?

Perhaps if we begin from the top in describing what you want to achieve...

--

Ken Snell
<MS ACCESS MVP>
 
G

Guest

LOL, to make life easier I got rid of the list boxes and used combo boxes
instead. This seesm to have solved my problem. Thank you so much for being
patient and persevereing in your aid. If I have anymore problems with this I
will surely return to confues you some more ;-)

Damon
 

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