Send UserForm value to another UserFrom

Pacman52

Active Member
Joined
Jan 29, 2009
Messages
416
Office Version
  1. 365
Platform
  1. Windows
Hi all I am really lossed on how to code a button on a small userform that will send the value in it to another userform

I have a main form called 'frmExpenses' part of this form is a textbox to record the total mileage. A user can either enter a number directly or thay can press a button called 'frmMileCalc' to enter the daily mileage to get a total.

'frmMileCalc' opens another form which allows a users to enter the daily mileage in various textboxes and totals it all in another textbox called 'txtTotalMileage'.
when the button 'buttonTransfer' is clicked I would like the total mileage value to transfer over to the orgonal form so that the user can carry on completing it and then writing all the values to the worksheet.

I've tried numerous methods to get this to work but no joy dispite many many searches on google ect.

Could someone please let me know firstly if this is achievable and if so how do I do it?

Many thanks

Paul
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Assuming the code is in the second form, it could simply be something like:

Code:
frmExpenses.textboxname.text = me.txtTotalMileage.Text
 
Upvote 0
Thanks Rory but I've tried that already and it didn't work but having just checked I've just noticed that frmExpenses closes when the mileage form opens

Could this be the issue?
 
Upvote 0
Even if it is closed, the code would load it. I suspect you have made the common mistake when switching from one form to another of attempting to unload the first form in the same code that loads the second form. That won't actually work. The code in the first form should hide the first form then show the second (at which point it will pause if the second form is modal, as is the default). The second form should not attempt to unload itself, it should merely hide and then the first form resumes control at which point it can read the relevant control in the second form (or a custom property that you create) and then unload the second form.
 
Upvote 0
Thanks for the info Rory. I hadn't actually coded the first form to do anyting I just assumed as I hadn't told it to close it would just hide itself but that just highlights my lack of knowlege on VBA but thankfully with great advice and support on this forum I'm learning fast !

Thanks again
 
Upvote 0
If you didn't code the first form to do anything, then it should just sit on screen when the other form opens and remain there when the other one closes.
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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