Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Populate MS Access List box from button onClick

Posted on 2014-10-28
13
Medium Priority
?
368 Views
Last Modified: 2014-11-02
I have forgotten how to do this.

Should the list box be defined with no control source?
What should I set as the list box data properties?

This is my button on click event:

Private Sub cmdTranslate_Click()

Me!lstTranslationResults.RowSource = "SELECT ln.Lang_Name, dc.Dict_Word FROM tblLanguage AS ln INNER JOIN tblDictionary AS dc ON ln.Lang_ID = dc.Lang_ID WHERE (((ln.Lang_ID) <> 1)) ORDER BY ln.Lang_Name "

End Sub

There is no error. The listbox does not populate.
The list box is set to display 2 columns. The SQL Statement returns 2 columns.

A quick example or reference will help.

Thanks,
0
Comment
Question by:Dovberman
13 Comments
 
LVL 7

Accepted Solution

by:
slubek earned 1200 total points
ID: 40409405
Try this:
Private Sub cmdTranslate_Click()

Me!lstTranslationResults.RowSource = "SELECT ln.Lang_Name, dc.Dict_Word FROM tblLanguage AS ln INNER JOIN tblDictionary AS dc ON ln.Lang_ID = dc.Lang_ID WHERE (((ln.Lang_ID) <> 1)) ORDER BY ln.Lang_Name "
Me!lstTranslationResults.Requery

End Sub

Open in new window

0
 

Author Comment

by:Dovberman
ID: 40409426
Thanks,

I had forgotten the need to Requery.

Oops, That did not fix it.

BTY, What is the VB line continuation marker?
0
 
LVL 85
ID: 40409444
You don't need to Requery if you set the RowSource.

Are you sure your SELECT statement actually returns records?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Dovberman
ID: 40409551
Yes,

Col1                 Col2
French              Alors
Hebrew              אז

lstTranslationResults
ColumnCount=2
ColumnWidths 1",1"

cmdTranslate
onClick is the only event procedure.

This is confusing.
0
 

Author Comment

by:Dovberman
ID: 40409591
I used this as a test:

Private Sub cmdTranslate_Click()

Me!txtTest.Text = "abc"

Nothing happens.

The event procedure is not called.
0
 
LVL 52

Assisted Solution

by:Gustav Brock
Gustav Brock earned 300 total points
ID: 40410095
It should raise an error, as the correct syntax is:

    Me!txtTest.Value = "abc"

But for testing it is better to pop a message:

    MsgBox "cmdTranslate clicked."

/gustav
0
 

Assisted Solution

by:Dovberman
Dovberman earned 0 total points
ID: 40410108
I commented out the list box statements.

Then I got the Set Focus error.

Applied the SetFocus method.
Me!lstTranslationResults.SetFocus

Now it works.

Thanks,
0
 
LVL 85
ID: 40410435
Sorry, but I'm not clear how the SetFocus method helped you to populate the Listbox. Could you please explain what the actual solution was to the problem you stated (i.e. populating the Listbox).
0
 

Author Comment

by:Dovberman
ID: 40411103
Error message received.  Cannot set a value for the control unless the control has the focus.

Once I set the focus, it worked. I remember this from years ago.  Try setting the controlsource of a listbox without setting focus.
0
 
LVL 85
ID: 40411359
Error message received.  Cannot set a value for the control unless the control has the focus.
No, you can set the RowSource of a Listbox without the Listbox having focus. I do it all the time (and just tried it on a test database, to be sure).

As far as ControlSource ... that's not what you asked, but still you can do that without the Listbox having the focus.

Not trying to be difficult, but your accepted solutions don't match up with what you asked ...
0
 

Author Comment

by:Dovberman
ID: 40411548
OK I will not argue. SetFocus works for me.
0
 
LVL 85
ID: 40411635
As I said, not trying to argue, just making sure that others who see this understand that SetFocus is not the solution. Simply put, you don't have to use SetFocus to modify the Rowsource (or Controlsource, for that matter) of your Listbox.
0
 

Author Closing Comment

by:Dovberman
ID: 40417984
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

926 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