ListBox Question

  • Thread starter Thread starter Shell
  • Start date Start date
S

Shell

In Access 2000

When a form is loaded, I have a list box which gets populated though a
query. The first column is the key and is hidden.

I can link back to this form, which has not been closed and I know when I
linked back or which I originally opened it. When I link back, I want to
have the original selection (which was done manually) un-selected (by code)
and a new selection automatically by code. I have the new key.

On the manual selection, I have fields populated by code. These fields need
to be repopulated by code, during the 'link back'.

Thanks
 
Hi Shell

You imply that this is not a multi-select listbox, so assigning it a new
value will both unselect the old item and select the new one.

From code within the form which contains the listbox:

Me![ListboxName] = <new key value>

From code outside the form which contains the listbox:

Forms("NameOfForm")![ListboxName] = <new key value>

I assume that "I have fields populated by code" means that you have an
AfterUpdate event procedure for your listbox which populates the fields.
The AfterUpdate proc will execute automatically only after a manual
selection, but you can call it from code after changing the selection in
code:

From within your form:

Me![ListboxName] = <new key value>
Call ListboxName_AfterUpdate

From outside your form:

Forms("NameOfForm")![ListboxName] = <new key value>
Call Forms("NameOfForm").ListboxName_AfterUpdate

In this case you should change the declaration of ListboxName_AfterUpdate
from "Private" to "Public".
 
Back
Top