Solved

Populate a listbox from combobox selection in MS Access 2007

Posted on 2010-08-15
4
621 Views
Last Modified: 2012-05-10
On my form I have a field called Symbol as a combobox. I want to populate a listbox with records where this value exists in a table. This is the code I have so far...

Private Sub Symbol_Change()
    Me!lstHolders.RowSource = "Select tbl_Stock_Postn.StockPosnID, tbl_Customer.AcctName, tbl_Stock_Postn.TOTAL, tbl_Stock_Postn.Holding" _
    & "FROM tbl_Customer INNER JOIN tbl_Stock_Postn ON tbl_Customer.ID = tbl_Stock_Postn.ACCTNAME" _
    & "WHERE tbl_Stock_Postn.Holding) = " & Me.Symbol & "ORDER BY tbl_Customer.AcctName"
    Me!lstHolders.Requery
End Sub

I get no results in the listbox. Can someone please direct me on what I am not doing correctly?
0
Comment
Question by:rawilken
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Emenizer
ID: 33442249
First of all: are you sure the query returns results?
Try it by puting it in a variant and then run trough the code By Step.

If your are sure it returns results, you have to populate the listbox (e.g.: http://www.exceltip.com/st/Fill_a_ListBox-control_with_values_from_another_workbook_using_VBA_in_Microsoft_Excel/410.html )
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 125 total points
ID: 33544205
I don't see where you are actually "connecting" to the Access database?
Are you trying to load these fields Horizontally of vertically?
How many records will your SQL be returning?

In any event, try something like this as a test:

Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = OpenDatabase("C:\YourFolder\YourDatabase")
Set rst = db.OpenRecordset("Select SomeStuff FROM YourTable")

rst.MoveFirst
 Do Until rst.EOF
    yourlistbox.AddItem rst!Somestuff
    rst.MoveNext
 Loop

rst.Close
Set rst = Nothing
db.Close
Set db = Nothing


This code should load a listbox (Vertically) with the values in the table Field.

;-)

JeffCoachman
0
 

Author Closing Comment

by:rawilken
ID: 33673971
Only partial answer but headed in right direction
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 33678255
Thanks,

But what would have been a "Full" answer?

AFAICT my post does what you requested

;-)

JeffCoachman
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

930 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

12 Experts available now in Live!

Get 1:1 Help Now