Link to home
Start Free TrialLog in
Avatar of Lawrence Salvucci
Lawrence SalvucciFlag for United States of America

asked on

ListBox on Access form

I have a subform that has a listbox on it. When I open the main form to a specific record I want the listbox on my subform to select the first record in it. I have tried so many variations of Me.lstItems.ItemData(0), etc. but none of them have worked. Can someone please share with me how I can have the first record in my listbox selected which will also highlight that record so I can see that it's actually selected?
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

first you need to specify where the listbox is

Me![subformcontrolname].form.lstItems.ItemData(0)

brb
Avatar of Lawrence Salvucci

ASKER

Should that go in the "On Open" or "On Load" event of the main form?
try placing the codes in Load and Current event of the form
of the main form or the subform?
of the main form
I put that code in both the On Load and On Current events of the main form and I am getting the following error:

"You entered an expression that has an invalid reference to the property Form/Report"
@Lawrence,

I can't determine the error if you are not going to post the codes that you used.
The code you posted:

Me![sfrmSalesOrderItems].Form.lstItems.ItemData (0)

Open in new window

ok... now I need to see your db
upload a copy of the db

try these codes
with Me![sfrmSalesOrderItems].Form.lstItems
    .Selected(0) = True
    .Value = .ItemData(0)
end with

are you sure that ![sfrmSalesOrderItems] is the name of the CONTROL that house your subform?
I cannot upload a copy of the DB. It's too big and has too many links to other sources, etc.

sfrmSalesOrderItems is the name of the SUBFORM. The name of the ListBox is lstItems
<sfrmSalesOrderItems is the name of the SUBFORM>
I am asking for the name of the CONTROL where the subform is.

in the design view of the main form, click on the edge of the subform and hit F4, click on the Other tab on the Property window and look what is listed in the Name property
sfrmSalesOrderItems is the name as well
SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In the On Current & On Load event of the main form?
try first the LOad event of the main form
Same error as before:

"You entered an expression that has an invalid reference to the property Form/Report"
well. there is something in your form that is causing this error.

create a blank db and import the main form and the subform, upload the new db
I will look into it more in a little bit. I have to move on to other tasks. I will post back when I create a blank DB and test it out in there.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial