Solved

ListBox on Access form

Posted on 2016-10-31
19
31 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
ID: 41866869
try placing the codes in Load and Current event of the form
0
 
LVL 1

Author Comment

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

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 119

Expert Comment

by:Rey Obrero
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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in query expression 3 31
ms access 2013, running .mdb 2 29
SQL profiler equivalent in MS-Access 3 41
how to link subforms ms/access VBA 6 26
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now