473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

select listbox value from access vba

hello freinds !!
i have created a listbox which populates 7 choices
i need to make a single selection out of 7 choices.

now when ever user makes the selection out of any of the choices then on a button click the few functions would be called like

begin:

if choice 1
then call function1
else if choice 2
then call function 2
else if choice3
then function3
....
....
...
end

i am looking out for some vba code... i am new to vba and i am just blank

any thoughts would be appreciated
thanks
Dec 9 '07 #1
1 2748
missinglinq
3,532 Expert 2GB
With the listbox named YourListBox and the button named YourCommandButton this code behind the command button will do it:

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourCommandButton_Click()
  2.  
  3. Select Case YourListBox
  4.  
  5. Case "Choice1"
  6. Call Function1
  7.  
  8.  Case "Choice2"
  9.  Call Function2
  10.  
  11.  Case "Choice3"
  12.  Call Function3
  13.  
  14.  Case "Choice4"
  15.  Call Function4
  16.  
  17.  Case "Choice5"
  18.  Call Function5
  19.  
  20.  Case "Choice6"
  21.  Call Function6
  22.  
  23.  Case "Choice7"
  24.  Call Function7
  25.  
  26.  End Select
  27.  
  28. End Sub
  29.  
But you don't actually have to have a button to click. You can simply use the listbox and when a choice is made theis code will run the selected code.

Expand|Select|Wrap|Line Numbers
  1. Private Sub YourListBox_AfterUpdate()
  2. Select Case YourListBox
  3.  
  4. Case "Choice1"
  5.  Call Function1
  6.  
  7.   Case "Choice2"
  8.   Call Function2
  9.  
  10.   Case "Choice3"
  11.   Call Function3
  12.  
  13.   Case "Choice4"
  14.   Call Function4
  15.  
  16.   Case "Choice5"
  17.   Call Function5
  18.  
  19.   Case "Choice6"
  20.   Call Function6
  21.  
  22.   Case "Choice7"
  23.   Call Function7
  24.  
  25.  End Select
  26. End Sub
  27.  
So use one set of code or the other, but not both!

Welcome to TheScripts!

Linq ;0)>
Dec 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
5
by: Melissa Cowan | last post by:
I am using Access 2000. I have the Developer's handbook and got the code for the mulit select listbox from there. It sends the selected value to another listbox, lstselected. What I need to do is...
5
by: Lisa | last post by:
Hello, I am new to using recordsets, and i am completly stuck with this one. I am trying to use a multi select list box to write records to a table. Something in my code is causing the same...
3
by: google | last post by:
Hello, I am trying to create a listbox that users can select multiple entries on. I want Access to put each on of those selections in a different row on a particular table. This table will also...
2
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the...
5
by: Matthew Wells | last post by:
I have a listbox set to simple multi select. For this example, users only select one item at a time. I have command buttons on the form for First, Previous, Next, Last, New (record). The form...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
2
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.