Solved

ListBox on Access form

Posted on 2016-10-31
19
33 Views
Last Modified: 2016-11-03
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
Comment
Question by:Lawrence Salvucci
  • 10
  • 9
19 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866860
first you need to specify where the listbox is

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

brb
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866865
Should that go in the "On Open" or "On Load" event of the main form?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866869
try placing the codes in Load and Current event of the form
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866872
of the main form or the subform?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866878
of the main form
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866883
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866886
@Lawrence,

I can't determine the error if you are not going to post the codes that you used.
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866890
The code you posted:

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

Open in new window

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866895
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
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866900
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866910
<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
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866914
sfrmSalesOrderItems is the name as well
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 500 total points
ID: 41866917
try these codes

 with Me![sfrmSalesOrderItems].Form.lstItems
     .Selected(0) = True
     .Value = .ItemData(0)
 end with
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866922
In the On Current & On Load event of the main form?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866926
try first the LOad event of the main form
0
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866943
Same error as before:

"You entered an expression that has an invalid reference to the property Form/Report"
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41866951
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
 
LVL 1

Author Comment

by:Lawrence Salvucci
ID: 41866968
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
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 41867001
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question