473,325 Members | 2,860 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,325 software developers and data experts.

How do I link commandbuttons to combobox selection?

Hi all,

I need to combine the action of a command button to be dependent on the selection in the Combo Box in order to fill the cell with the selection that the combo box refers to.

For instance, if I have three A columns,

A2: Shoes
A3: Socks
A4: Gloves

And two rows in B and C:

B1: Video
C1: Article

I have a userform where my command buttons are "Started" and "Published".

In my userform, the ComboBox lists Shoes, Socks, Gloves

Clicking Started or Published would place an "S" or a "P" in a cell. I want the cell that is filled with an S or P to be dependent on my ComboBox selection.

So if I choose Socks and clicked Started, an S would appear in B3. If I click Shoes in the ComboBox, then click the same Started command button, an "S" would appear in B2.

Do you know what coding I should use to make this happen, and if there's a shortcut or trick if I have a long list of columns?



Thanks!!
Dec 26 '18 #1
2 5514
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2.     a = "You clicked on " + UserForm1.ComboBox1.Value + "which is option number: " + Str(UserForm1.ComboBox1.ListIndex)
  3.     MsgBox a
  4. End Sub
the ListIndex starts counting from 0.
Dec 29 '18 #2
SioSio
272 256MB
Luuk writes tips.
In your writing, I don't know what would go in column C, but I assumed that when "Published" was pressed, "P" would go in
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2. With ComboBox1
  3. Cells(.ListIndex + 2, 2).Value = "S"
  4. End With
  5. End Sub
  6.  
  7. Private Sub CommandButton2_Click()
  8. With ComboBox1
  9. Cells(.ListIndex + 2, 3).Value = "P"
  10. End With
  11. End Sub
  12.  
Dec 24 '19 #3

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

Similar topics

2
by: jen | last post by:
i have select query that returns multiple records and populates a combobox/pulldown. once a selection from the pulldown is selected, i need to reference two or three fileds from the previous...
11
by: billa856 | last post by:
Hi, I have project in MS Access.In that I have one form in which there is one combobox .I want to know when I select an item from that combobox and click on submit button then it should open a...
4
by: Mtek | last post by:
Hi, We have a combo box on our page, which gets populated via a MySQL Query in PHP. What we want to do is to print the values on the page in a table that correspond the to selection from the...
1
by: Rosie | last post by:
I have a main form with header info w/ 'tHeader' as the control source. I have a subform with 'tDetail' as a control source. They're strung together by a field named MA_ID. This works...
0
by: pavanip | last post by:
Hi, I am facing problem with combobox in gridview.I have used combobox in gridview and i am binding data to gridview combobox from database. If i click 2 times on combobox then it is showing the...
1
by: Emily Walshaw | last post by:
I'm sorry, I know this has been asked a million times, but am completely new to access and need idiot proof help. I have a database and I am struggling to get a field to update based on a combobox...
0
by: Moorthi chinna | last post by:
how to reload combobox in datagridview based on combobox selection in datagridview?
4
Seth Schrock
by: Seth Schrock | last post by:
I have a database that is keeping track of returned mail. Each piece of returned mail has a status. I want to be able to view reports for all the returned mail in each status. I could create a...
10
by: simaonobrega | last post by:
Dear Bytes community, Framework: I have created a form using the "Form Design" tool. On the form property sheet, it was added to the Record Source the table which contained the fields that I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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

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.