Solved Select column value in a listbox (1 Viewer)

When using a Class module, the advantage is that it is a Black box. You do not ever need to touch the code to use it. You just need to know how to intialize it and call its methods and functions. So you import as is the class.
To do that in your database you will import using the import from database function the class
You should then see a Class in the navigation called "ColumnListBox"
That is the beauty of object oriented programming. You do not need to know how the code works just how to use it.

If you look at my example there is no code in the form, all the code is in the class. It looks to me that you copied code into your form's module.
I am not advocating this as a good approach, there are probably 100s of ways to make this interface. But this is a simple exercise for learning how to use a custom classes.

You might like to try these classes which are Find as you type listboxes. Same thing you need to import the classes. Then look at the forms and see you you intialize the class. Should be 1 line of code to make the FAYT work. The demo has 10k records but you can find a name very quick.

But the idea of a single column that changes with the radio button, seems like that would be a good user interface. Like I said there are probably lots of ways.
 

Attachments

moke123 -Very nice idea, but should a certain filtered list exceed the number of buttons or form fields then what?
 
Last edited:
Coincidentally, I was asking in another forum, how one would handle an option group, where the values came from a table, like one would do for a combo/listbox.?
I have only ever used them with hardcoded values like Male/Female, but with that subject these days, there now appear to be many more options
?
 
SOLVED - Works Perfectly how I initially wanted it to. A couple of things to take note of.
1. It won't work if you set the listbox.columnwidths with code. you must do it thru the access application interface.
2. Following MajP's examples for FindAsYouTypeListbox, in the actual form code I had to public declare CLB as ColumnListBox at the top of the forms code

The pertinent form code to initialize the class module:
Code:
Private Sub Form_Load()
    Set CLB = New ColumnListBox
    CLB.Init Me.lstDx
.......

And my Click Code:
Code:
Private Sub lstDx_Click()
    'MsgBox CLB.ClickedColumn
    'MsgBox CLB.ClickedColumnValue
    Forms!BillingTxLU!Dx = CLB.ClickedColumnValue
    DoCmd.Close acForm, Me.Name
End Sub

Thank you everyone, especially MajP for the ideas and help.
 
I noticed in post# 19 where you posted your code, that you only had Option Compare Database. You should always also declare Option Explicit underneath that. You'll save yourself a lot of frustration.

1. It won't work if you set the listbox.columnwidths with code. you must do it thru the access application interface.
I haven't tested it but you may be able to, provided you do it prior to initializing the class. Try it.
 
Moke123. Thank you. I'll give it a try. I'm still trying to understand Class Modules and how they work. You make a lot of sense.
 
I'm still trying to understand Class Modules and how they work
This thread provides some step by step on how to build your own classes to do similar things.
 
@craigachan
FYI. When using an object you can do Declare/Initialize and Instantiation in one or two steps. I did it in one step you did it in two. This may have taken you time to figure out. This is done using the NEW keyword.

Two steps
Code:
Private CL as ColumnClickBox  ' Declare variable only

Private Sub Form_Load()
    Set CLB = New ColumnListBox 'Instantiation
     ...
end sub

One Step
Code:
Private CL as NEW ColumnClickBox  ' Declare and Instantiations

Private Sub Form_Load()
     ...
    'NO CODE NEEDED HERE to Set = New Columnlistbox
end sub
 

Users who are viewing this thread

Back
Top Bottom