populating my listbox

G

Guest

I am attempting to populate my Listbox with data, based on a selection in a
combo box.
What I am finding is that the Listbox is being populated with the select
statement.
Obviously, I'm doing something wrong, just don't know what it is.

Should I also be putting some kind of code in the Form_Load event? I don't
think I should, because the contents of the Listbox won't be determined until
the after the combo box selection right?

Sample Code - For the after_update event of the combo box.
Private Sub cboBpr_AfterUpdate()

On Error Resume Next

cboBpr.SetFocus

Dim db As DAO.Database
Dim strSQL As String
Dim strWhere As String
Dim rs As DAO.Recordset

strWhere = "WHERE BPRNumber = '" & cboBpr & "'"
strSQL = "SELECT BPRNumber FROM tblBPRNumber" & strWhere
strSQL = strSQL & "ORDER BY BPRNumber;"

Me.txtArea = rs("Area")
Me.lstSops.RowSource = strSQL

End Sub
 
M

Michel Walsh

Hi,


Sounds like a space is missing between tblBPRNumber and the keyword WHERE.
Add the extra spaces, and in doubt, add one again (as example, before the W
of WHERE and before the O in ORDER BY).

You can

Debug.Print strSQL


to see the statement, once it is ready to be used, in the immediate debug
window.


I assume BPRNumber has text values, if not, if it is a number, remove the '
delimiters.


Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top