472,958 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 5284
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.