Super New to Access - List Box Help (2 Viewers)

austinsneeze

New member
Local time
Yesterday, 22:28
Joined
May 5, 2023
Messages
6
Hi,

I am new to Access and I'm trying to figure out how to show records on my form based on what was selected from my list box. I tried to search the forum but had no luck. I know there is a simple solution but I'm so new, I don't know what to search for.

Thank you in advance.
 

Attachments

  • Screenshot 2023-05-05 074538.png
    Screenshot 2023-05-05 074538.png
    62.3 KB · Views: 56
Solution
The boundColumn property tells you from which column the value of the listbox comes from.
So the code provided will work regardless of the number of visible columns. It will always pull the value from the bound column

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:28
Joined
May 21, 2018
Messages
8,554
Lets assume your listbox holds the material ID in the first column and that is the bound column (you can hide this if you want). Then you have other columns like number and name etc.

on list23 afterupdate event (find the afterupdate event in properties and click on "...". Select code not macro"
This will build a vba event procedure

if not isnull(me.list23) then me.recordset.findfirst "MtrlID = " & me.list23
If your materialID is a string
if not isnull(me.list23) then me.recordset.findfirst "MtrlID = '" & me.list23 & "'"
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:28
Joined
May 21, 2018
Messages
8,554
If you do a subform it is easy. Assuming again the listbox is bound to the materialID
Then in the subform controls
Parent Link Fields: [list23]
Child Link Fields: [MrlID]
 

austinsneeze

New member
Local time
Yesterday, 22:28
Joined
May 5, 2023
Messages
6
Lets assume your listbox holds the material ID in the first column and that is the bound column (you can hide this if you want). Then you have other columns like number and name etc.

on list23 afterupdate event (find the afterupdate event in properties and click on "...". Select code not macro"
This will build a vba event procedure

if not isnull(me.list23) then me.recordset.findfirst "MtrlID = " & me.list23
If your materialID is a string
if not isnull(me.list23) then me.recordset.findfirst "MtrlID = '" & me.list23 & "'"
BLESS YOU this worked. Thank you.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:28
Joined
Feb 28, 2001
Messages
27,223
First, since that was your post #1: Hello and welcome to the forum.

Second, a part of the problem that you will have here for a little while is, as you yourself noted, nomenclature. You don't know the words to use for a given problem. Frustrating though it may be, you should resign yourself to fumbling around until you pick up more of the useful terms for what you want to do. You will pick things up.

May I suggest your attention to a feature of the Xenforo software that runs this forum? Once you have posted your question, look at the bottom of a thread page to see "Similar Threads" - usually five threads filed by others that seem more or less similar to your problem.

Your question is perhaps a little bit ambiguous. It is that way because you aren't aware of the factors that go into providing an answer. Notice that you got several alternatives among the answers. That is because it wasn't quite clear as to exactly what you wanted. You could have been asking about returning a single record, or simply filtering the form so that it only shows a subset of the total number of records available to that form. (I took it as "subset of larger number of records with the ability to move between records.")

Another part of the question has to do with what you show in your list box. You (obviously) show a list and select something from it. But from where did Access get this list? How does it relate to the records being shown on the main form.

Providing details such as I mentioned will enable us to give you more specifically directed solutions. "Asking the right question" is amazingly hard until you see the trick to it: Provide us with a context in which your proposed/desired actions will occur. Once we know (a) what you want to do and (b) the context in which this will occur, we can help you a lot better.

You can look at the responses you got and decide if they tell you enough. BUT there is no harm in adding further comments, explanations, and questions to this thread. In fact, it is expected and quite commonplace. Since I'm not sure of your context, I won't offer another solution until you come back with other comments and questions as follow-up. But I thought you might like a little push in a good direction for future questions.

Finally, I might suggest some reading. When you want to do something that changes the behavior of a form, report, or control, you often need to do it in a context that exists only after the time that you opened the thing you want to somehow change. This usually requires either some very clever control definitions OR more commonly, you use an EVENT PROCEDURE to make changes.


So what I just did is gave you a key phrase to look up. Call it a contribution to your vocabulary if you didn't know anything about events and event procedures yet.
 

austinsneeze

New member
Local time
Yesterday, 22:28
Joined
May 5, 2023
Messages
6
Thank you for the feedback! And I do have another question.

I need to find a record in my form based on multiple columns in a list. The record source is from a table. I have four columns, but the first one is hidden. I need to double-click on one of the rows from my list to update the form (which is also linked to my table).

The first line of code worked for me, but there were only two columns in my list box (the MtrlID and the MtrlNm, and the MtrlID was hidden).

Code:
Private Sub lstMtrls_DblClick(Cancel As Integer)

If Not IsNull(Me.lstMtrls) Then Me.Recordset.FindFirst "MtrlNm = '" & Me.lstMtrls & "'"

End Sub

*Edit: I misnamed my list name, but have updated to the correct name.
 

Attachments

  • Screenshot 1.png
    Screenshot 1.png
    100.9 KB · Views: 43
  • Screenshot 2.png
    Screenshot 2.png
    48.4 KB · Views: 43

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:28
Joined
May 21, 2018
Messages
8,554
The boundColumn property tells you from which column the value of the listbox comes from.
So the code provided will work regardless of the number of visible columns. It will always pull the value from the bound column
 
Solution

austinsneeze

New member
Local time
Yesterday, 22:28
Joined
May 5, 2023
Messages
6
The boundColumn property tells you from which column the value of the listbox comes from.
So the code provided will work regardless of the number of visible columns. It will always pull the value from the bound column
Thanks again! This worked, too
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:28
Joined
May 21, 2018
Messages
8,554
FYI. The value of the listbox is the value of the bound column. You can get the values of other columns using the listbox column property

txtBoxMaterialNameSelected = list23.column(1)

This is a zero index property so column(0) is actually the first column, and column(1) is actually the second column
 

Users who are viewing this thread

Top Bottom