Edit listbox entries (1 Viewer)

Kuleesha

Member
Local time
Today, 09:35
Joined
Jul 18, 2021
Messages
50
Hi,

I am trying to create a form where i have a list box from which I want to choose items which can be populated into a textbox bound to a field in a table.
1. I need to be able to enter multiple values into the textbox using the list box
2. I need to be able to remove an already entered item by reclicking on the list box entry
3. I need to be able to manually enter values which are not in the listbox into the same textbox and to edit values that have already been entered into the textbox

I tried various things without success. Is this possible with a list box? Is there a better way to achieve same result?

Thanks in advance
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:05
Joined
Oct 29, 2018
Messages
16,572
Hi. Should be possible. On #3, are you saying you want to enter and modify values in the Textbox without using the Textbox?
 

Kuleesha

Member
Local time
Today, 09:35
Joined
Jul 18, 2021
Messages
50
I want to be able to edit the values that have already been entered into the text box (using the list box) by typing inside the textbox.
This is a bound text box so the edits have to be reflected back in the related table.
Thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:05
Joined
Oct 29, 2018
Messages
16,572
I want to be able to edit the values that have already been entered into the text box (using the list box) by typing inside the textbox.
This is a bound text box so the edits have to be reflected back in the related table.
Thanks
Okay, just trying to understand. Why can't you do that already? How exactly are you populating the Textbox with the items selected from the Listbox? You should be able to then click into the Textbox and then type away, right?
 

Kuleesha

Member
Local time
Today, 09:35
Joined
Jul 18, 2021
Messages
50
I have created a small sample database to indicate what I need to do (see attached)
I have a list box which uses values from a table (table InvestigationTemplate) in its row source. The control source of this list box in a field called InvestigationsOrdered in another table (table Patient). The text box I want to enter data into is also on the same form and has its control source also to same InvestigationsOrdered field.
When I have the multiselect property of the list box set to none, I can enter values into the textbox using the listbox and also edit these data / enter new data manually inside the text box. But this way I can only choose one value from the listbox. When I turn on multiselect property, I cannot enter data at all using the listbox but can manually enter data into textbox.
I need to be able to
1. enter multiple values into the textbox using the list box
2. remove an already entered item by reclicking on the list box entry
3. manually enter values which are not in the listbox directly into the textbox

Please help.
 

Attachments

  • Investigations.accdb
    544 KB · Views: 101

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:05
Joined
Oct 29, 2018
Messages
16,572
Hi. Not sure if this is what you want, but take a look.
 

Attachments

  • Investigations.zip
    25.5 KB · Views: 31

Kuleesha

Member
Local time
Today, 09:35
Joined
Jul 18, 2021
Messages
50
Thank you loads. Exactly what i was looking for.
One small thing - this creates a carriage line at the biggening of the entries also. Anyway to get around this ? My vba is pretty poor so can't workout how to get around this.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:05
Joined
Oct 29, 2018
Messages
16,572
Thank you loads. Exactly what i was looking for.
One small thing - this creates a carriage line at the biggening of the entries also. Anyway to get around this ? My vba is pretty poor so can't workout how to get around this.
I think this one covers that now.
 

Attachments

  • Investigations.zip
    25.1 KB · Views: 55

moke123

AWF VIP
Local time
Today, 00:05
Joined
Jan 11, 2013
Messages
2,562
here's another alternative
 

Attachments

  • Investigations (1).accdb
    700 KB · Views: 64

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:05
Joined
Feb 19, 2002
Messages
33,213
Sorry, I couldn't stand it so I'm posting the properly normalized solution.

It is always wrong to store multiple attributes in a single field. That is why First Normal Form specifies that all attributes should be atomic. This poor practice may not come back to bite you for a while but eventually it will.

At some point, you will probably want to store details about the investigations. Using the proper schema will give you a place to put that related data and the subform will give you a path to a form that shows the details of an investigation.
 

Attachments

  • Investigations_Pat.accdb
    704 KB · Views: 93

darrenislearning

New member
Local time
Today, 12:05
Joined
Aug 9, 2021
Messages
24
@theDBguy , I tried to follow your sample file and will have error when empty and it does not work like yours (e.g. move to the first line) when remove.
 

Attachments

  • Test Listbox.zip
    41.2 KB · Views: 60

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:05
Joined
Oct 29, 2018
Messages
16,572

Attachments

  • Test Listbox.zip
    30.5 KB · Views: 35

darrenislearning

New member
Local time
Today, 12:05
Joined
Aug 9, 2021
Messages
24
Give this one a try...
Thanks, it works. If I want to expand the course list, which value should i change in the afterupdate? E.g. I got 10 courses.

Edit: I tried on new record, when i select the listbox item, it will be reflected at the 2nd item. (with a line break before value)
 

Attachments

  • lstbox.PNG
    lstbox.PNG
    8.1 KB · Views: 57
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:05
Joined
Oct 29, 2018
Messages
16,572
Thanks, it works. If I want to expand the course list, which value should i change in the afterupdate? E.g. I got 10 courses.

Edit: I tried on new record, when i select the listbox item, it will be reflected at the 2nd item. (with a line break before value)
Try this one...
 

Attachments

  • Test Listbox.zip
    32.1 KB · Views: 61

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:05
Joined
Feb 19, 2002
Messages
33,213
theDBGuy loaded the bullets in your gun for you but in the long run, you would learn more and have a better foundation going forward if you did this the right way. Your name implies that you are interested in learning but maybe not.
 

moke123

AWF VIP
Local time
Today, 00:05
Joined
Jan 11, 2013
Messages
2,562
As Pat points out, the correct way to do this is to use a junction table with each record recording the primary key of the student table and the primary key of the course table. You can then show the courses each student is enrolled in using a subform or you can use the multi-select listbox which will show the selected values from the junction table.
The attached example shows both ways to display the information. The records are added or deleted from the junction table in the after update event of the multi-select listbox.
 

Attachments

  • StudentCourses.accdb
    652 KB · Views: 64

Users who are viewing this thread

Top Bottom