Solved

ListBox on Access form

Posted on 2016-10-31
19
29 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

708 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

16 Experts available now in Live!

Get 1:1 Help Now