Lawrence Salvucci
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?
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
ASKER
of the main form or the subform?
of the main form
ASKER
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"
"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.
I can't determine the error if you are not going to post the codes that you used.
ASKER
The code you posted:
Me![sfrmSalesOrderItems].Form.lstItems.ItemData (0)
ok... now I need to see your db
upload a copy of the db
try these codes
with Me![sfrmSalesOrderItems].F orm.lstIte ms
.Selected(0) = True
.Value = .ItemData(0)
end with
are you sure that ![sfrmSalesOrderItems] is the name of the CONTROL that house your subform?
upload a copy of the db
try these codes
with Me![sfrmSalesOrderItems].F
.Selected(0) = True
.Value = .ItemData(0)
end with
are you sure that ![sfrmSalesOrderItems] is the name of the CONTROL that house your subform?
ASKER
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. 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
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
ASKER
sfrmSalesOrderItems is the name as well
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In the On Current & On Load event of the main form?
try first the LOad event of the main form
ASKER
Same error as before:
"You entered an expression that has an invalid reference to the property Form/Report"
"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
create a blank db and import the main form and the subform, upload the new db
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Me![subformcontrolname].fo
brb