Solved

Link subform to listbox

Posted on 2011-03-13
4
585 Views
Last Modified: 2012-05-11
Hi Experts,

I have a form that has a listbox and subform. the subform is linked to the listbox. it works but the issue I am having is that the subform does not display the data unless I click on the listbox record. The listbox display one records each time the form is opened. but somhow, the record showing in the list box is not selected till I manulay click on it. I am not sure if there is a way that when the form loads, the record in the list box to be slected.

The listbox name is OrgGlID
subform is GLDetails_subform
0
Comment
Question by:HappyAlways
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Khalid Mehmood Awan
ID: 35125374
you should select the desired value available in listbox on subform by adding code lines in ON_LOAD function of sub form.

You will get the on_load function by double clicking the subform in design view.
if you are retrieving the values from a database, select them in the same ON_LOAD function.
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 35126852
Use the OnCurrent event of the form to read and set to top value from the listbox:
Private Sub Form_Current()

  With Me!YourListBox
    .Value = Abs(.ItemData(.ColumnHeads))
  End With
  
End Sub

Open in new window

/gustav
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 35130441
Cactus,

Don't you mean:

    .Value = .ItemData(abs(.ColumnHeads))


.ColumnHeads should return a 0 or -1
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 35130528
Of course! Thanks.

/gustav
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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

707 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

11 Experts available now in Live!

Get 1:1 Help Now