List Box Source Change

Pick9811

Registered User.
Local time
Today, 19:21
Joined
Apr 29, 2012
Messages
14
Hello again all,
My current problem involves a listbox, which I want to show me data from different tables when I hit a button like "View Table One" and then change when I click "View Table Two". Some of the tables have different numbers of columns, and I think I cracked part of the code, here's what I have so far:

Private Sub ViewTableOne_Click()

LstBox.ColumnCount = 2
Me.LstBox.ColumnWidths = "0.6 in, 2.6 in"
LstBox.ControlSource = "TableOne"

End Sub

When I click the "ViewTableOne" button, it changes the ColumnCount and Widths fine, but displays no data.

Can anyone offer me a hand? I plan on having this ListBox display data for easy viewing from 5 or 6 different table ranging from one to three columns.

Thanks!
Pick
 
By the way, I changed all the names to generic stuff so it would be easy to understand (so everyone doesn't think I named my List Box "LstBox" :)
 
I've been thinking about it... and I might have a solution for myself.

I can stack 5 listboxes on top of each other, with each formatted the way I want them for a particular data set. Then I'll set them visible or not based on the button selection... this seems to me a sloppy way to do it, and I know there must be a better way.
 
I finally got it... figured I'd post the solution on here in case anyone else needed it.

My Code for the First Button takes into account I want it to display two columns of data, I had to set column count for three and make width "0" inches to hide the "ID" column. Code for the button called "View Table One" is:

Private Sub VwTableOne_Click()
LstLabel.Caption = "Items in Table One"
LstBox.ColumnCount = 3
LstBox.ColumnWidths = "0 in, 0.6 in, 2.6in"
LstBox.RowSource = "Table1"
End Sub

So that changes the Caption to say what it's displaying, sets the column count to three, hides the first column, sets appropriate widths for the next two, and lastly... where my problem was sets the RowSource to Table1. So the next button's code looks like this:

Private Sub VwTableTwo_Click()
LstLabel.Caption = "Items in Table Two"
LstBox.ColumnCount = 2
LstBox.ColumnWidths = "0 in, 2.6in"
LstBox.RowSource = "Table2"
End Sub

So that one only displays one column and hides the ID column, but still changes the caption and RowSource. I thought I had tried messing with the RowSource already which was probably my hangup.

In any case the stacked list boxes was a terribly sloppy idea :cool:

Much easier than I made it...

Thanks to those who took a look, and I apologize if my question wasn't clear enough to solicit a response.
Pick
 

Users who are viewing this thread

Back
Top Bottom