Listbox Default Record

  • Thread starter Thread starter Craig
  • Start date Start date
C

Craig

I'm using Access 2K. I have 2 listboxes on a form and I
want the first record in each listbox to be highlighted
(default) when the user opens the form.

The code I have in the 'on open' event for the form is the
following:
Me!Listbox1Name.Value = Me!Listbox1Name.ItemData(0)
Me!Listbox2Name.Value = Me!Listbox2Name.ItemData(0).

The problem I have is that this works only for Listbox1.
The first record in Listbox2 does not highlight. Could
this be because of the underlying recordsource query?
FYI: The query for Listbox1 is a simple query of 2 fields
from a table. The query for Listbox2 is a Union query of
two fields from 2 different tables.

Why should it matter? Not to be funny or anything, but
the first record in a listbox is the first record in a
listbox.

Thx for any and all help.

C
 
Craig said:
I'm using Access 2K. I have 2 listboxes on a form and I
want the first record in each listbox to be highlighted
(default) when the user opens the form.

The code I have in the 'on open' event for the form is the
following:
Me!Listbox1Name.Value = Me!Listbox1Name.ItemData(0)
Me!Listbox2Name.Value = Me!Listbox2Name.ItemData(0).

The problem I have is that this works only for Listbox1.
The first record in Listbox2 does not highlight. Could
this be because of the underlying recordsource query?
FYI: The query for Listbox1 is a simple query of 2 fields
from a table. The query for Listbox2 is a Union query of
two fields from 2 different tables.

Why should it matter? Not to be funny or anything, but
the first record in a listbox is the first record in a
listbox.

Does the second list box have its MultiSelect property set to anything
other than "None"?

If you open the form in question, then press Ctrl+G and in the Immediate
Window enter

Forms!YourFormName!Listbox2Name =
Forms!YourFormName!Listbox2Name.ItemData(0)

(correcting the form name and list box name), does it work? Do you get
an error message?
 
Back
Top