transfer combobox value to new userform

markdoughty

Board Regular
Joined
Nov 4, 2010
Messages
226
Ive been trying to no avail to take the value of a combobox on userform1, and, to place it into a textbox on userform2.

I have tried various code senarios but think i might be missing something more key to the point that im transferring values between userforms.

this is just one of the codings i tried within the inialization section of userform2.


HTML:
workbook.userform1.combobox1.Value = userform2.TextBox1.Value

any help much apprieciated
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You have the code the wrong way round. You should look to name the objects like txt for Textbox and frm for the userform name. I am assuming that the form you are in is the second form and that the workbook name you are using is open as well.

Code:
TextBox1.Value=workbook.userform1.combobox1.Value</pre>
 
Upvote 0
Trevor

Thanks, sometime i could slap myself. I should of known to work the code backwards.

Any ways, what you have suggested does work, but rather than giving me the value of the combobox, it gives me the row number from the sheet where the combobox value is stored?

Do i need to Dim the combobox.

I tried Object " Object variable or with block variable not set" error returned.

and string returned "with object must be user defined, object or variant"

Variant returned "object required"

?
 
Upvote 0
Mark

Are both comboboxes on userforms?

The reason I ask that is because if they are you should get the value from the combobox not a row number.

You would only get a row number (index) if a combobox is located on a worksheet.

PS What's workbook?
 
Upvote 0
Norie

I did originally have two comboboxes on seperate "userforms" not sheets. I did wonder if the meer fact that they were comboboxes and needed " selecting" may be the problem, so converted to a combobox on the first userform and a textbox on the second userform.

However i have now tried the below code both ways, (cbo being the comboboxes) and in both instances it gives me the row number of the sheet holding the value of the first userforms combobox not the value of the combobox.

The value, just in case it makes a difference is a " alpha / Numeric" combination. For instance SA-00010010.

A fixed order number not a calculation, which i believe means it is a "string"

HTML:
cbosalesordernumber.Value = SimpleSheet.addproducts.cbosalesordernumber.Value
 
Upvote 0
Please explain what SimpleSheet is here?

Also, what are the fixed order number and calculation you are referring to?
 
Upvote 0
Norie

Simplesheet is the excel project. The fixed order numbers are the value of the combobox, which are themselves are invoice numbers which do not change, hence not "calculations"

Hope this helps
Mark...
 
Upvote 0
Mark

I honestly don't know what you mean by 'excel project', the only thing I can think of is the workbook's VBProject which I'm pretty sure you wouldn't need here.

How have you defined SimpleSheet in the code?


If I was transferring the selected value from one combobox to another I would simple use this.

Code:
UserForm2.Combobox2.AddItem UserForm1.Combobox1.Value

Note, this actually adds the selected value in Combobox1 to the list in Combobox2 - I don't see why you would want to set the value of another combobox from another.

Perhaps I'm totally missing the whole thing here.:)
 
Upvote 0
Norie

tried your suggestion, but again it gives me the same result, the row number of the sheet containing the value of the combobox not the value of the combobox?

Why do you need one combobox to show the value of another combobox you ask?

In excel terms you dont of course, but im assuming that people who may one day use my userforms are not totally computer friendly and unless they can see something in front of their face they just wont believe it....

So in explanation, my userform1, is starting a process of collecting info, only theres so much info it wont all fit on one form, so the user is promted to go to userform2 to finish collecting the info.

The value of the two comboboxes provides the user with the self-assurance that they are still collecting info against the same subject....

Mark...
 
Upvote 0
Mark

If you just set the value of the second combobox to the value of the first what happens when the user makes another selection from the first combobox?

As for only transferring the row value, how have you populated the first combobox?
 
Upvote 0

Forum statistics

Threads
1,206,711
Messages
6,074,465
Members
446,071
Latest member
gaborfreeman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top