User Form controls still executing after Unload

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,632
Office Version
  1. 365
Platform
  1. Windows
I am using a UF that the user enters details on that need to be appended to a range in a worksheet.

Once the data has been added and pasted into a holding worksheet, the UF is closed via an Unload commande but when some of the non UF code is executing, the code for some controls are executing.

E.g.
Code:
strCategory = rngGoodsOut.Offset(0, 0)
   strPerson = rngGoodsOut.Offset(0, 1)
   dtDateOut = rngGoodsOut.Offset(0, 2)
   strItem = rngGoodsOut.Offset(0, 3)
   lngQty = rngGoodsOut.Offset(0, 4)
All this is in a module and not behind the UF and each of the variables refer to items that were addedin the UF so strPerson was added via a combobox, dtDateOut was added via a textbox.

Now when each of these lines of code execute the combobox control for selecting the person executes 'cbPerson_Change'.

I have no clue as to why this is happening and wondered if anyone else has experienced this odd behavior.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If I read what you are describing correctly, it appears that you initialized variables located in a public code module with values entered via a UF. Those variables do not "unload" when the UF unloads. Only the variables in the UF code module are destroyed when the form unloads. So the varibles in a public code module will hold the value until they are assigned new values or the procedure ends, whichever comes first.
 
Upvote 0
Ah!!!

So if I am needing to assign a control value to a variable (CbPersoron to strPerson), how do I do that without declaring strPerson as public?
 
Upvote 0
Ah!!!

So if I am needing to assign a control value to a variable (CbPersoron to strPerson), how do I do that without declaring strPerson as public?

I am not sure what you are asking, but this is how it works.
Variables assigned inside a macro live and die with the macro.
Variable values can be passed from one macro to another and will live in the receiving macro until it completes at which point the varibles die.
Public variables can be used by any macro and their values are determined based on how they are declared, eg. some values of public variables might change during runtime of macros, but constants do not change during runtime of macros.
Values for variables passed from one code module to another must be passed by reference.

Values for controls on a UF can be used in variables in pulbic marcros if the UF is open during the runtime of a public macro,

Don't know how much help this will be, but it is the basic guide as I understand it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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