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
Solved

Populate a listbox from combobox selection in MS Access 2007

Posted on 2010-08-15
4
644 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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