By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,841 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,841 IT Pros & Developers. It's quick & easy.

select listbox value from access vba

P: 1
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
Share this Question
Share on Google+
1 Reply


missinglinq
Expert 2.5K+
P: 3,532
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

Post your reply

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