[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ListBox on Access form

Posted on 2016-10-31
19
Medium Priority
?
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

656 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