Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 57
  • Last Modified:

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?
0
Lawrence Salvucci
Asked:
Lawrence Salvucci
  • 10
  • 9
2 Solutions
 
Rey Obrero (Capricorn1)Commented:
first you need to specify where the listbox is

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

brb
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Should that go in the "On Open" or "On Load" event of the main form?
0
 
Rey Obrero (Capricorn1)Commented:
try placing the codes in Load and Current event of the form
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
of the main form or the subform?
0
 
Rey Obrero (Capricorn1)Commented:
of the main form
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
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"
0
 
Rey Obrero (Capricorn1)Commented:
@Lawrence,

I can't determine the error if you are not going to post the codes that you used.
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
The code you posted:

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

Open in new window

0
 
Rey Obrero (Capricorn1)Commented:
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?
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
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
0
 
Rey Obrero (Capricorn1)Commented:
<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
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
sfrmSalesOrderItems is the name as well
0
 
Rey Obrero (Capricorn1)Commented:
try these codes

 with Me![sfrmSalesOrderItems].Form.lstItems
     .Selected(0) = True
     .Value = .ItemData(0)
 end with
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
In the On Current & On Load event of the main form?
0
 
Rey Obrero (Capricorn1)Commented:
try first the LOad event of the main form
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
Same error as before:

"You entered an expression that has an invalid reference to the property Form/Report"
0
 
Rey Obrero (Capricorn1)Commented:
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
0
 
Lawrence SalvucciInformation Technology ManagerAuthor Commented:
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.
0
 
Rey Obrero (Capricorn1)Commented:
see this sample db

open the form Customers and see that te first item in the listbox in subform is selected
Q_28979975.accdb
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now