[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Populate a listbox from combobox selection in MS Access 2007

Posted on 2010-08-15
4
Medium Priority
?
697 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
[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
  • 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 375 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

650 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