selecting the default value from a List Box

G

Guest

How do I input the first item of a list box to the relevant field of a
database, if the user doesn't select any other item. I want the first item to
be the default entry to the field if the user did not select anyother value.
Am I expecting too much from a simple list box?

Toyfixer
 
B

Brendan Reynolds

ToyFixer said:
How do I input the first item of a list box to the relevant field of a
database, if the user doesn't select any other item. I want the first item
to
be the default entry to the field if the user did not select anyother
value.
Am I expecting too much from a simple list box?

Toyfixer


The following code will select the first item in the list if no other item
is selected. In this example 'lstTest' is the name of the listbox.

Private Sub Form_Current()

If IsNull(Me.lstTest.Value) Then
Me.lstTest.Value = Me.lstTest.ItemData(0)
End If

End Sub
 
G

Guest

Hi Brendan
Thanks for the reply, but it doesn't seem to work with control source set to
the field in the table.(listbox control source set in the properties dialog
box, set to the field in the table)
Am I missing something here?

Toyfixer
 
G

Guest

Thanks for the reply Klatuu,

I worte the line in the After update event of the previous combo box. But it
doesn't seem to write the value to the table.

Toyfixer
 

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