![]() |
Unable to pass variable between Userforms
I have thoroughly searched the group for an answer to this problem, but
nothing seems to fit the bill. I have created a userform that allows the user to select a variety of options in order to process incoming data files. Since our group is currently in the middle of two different processing years, I need to have the user indicate the year in which they are working. This is done with an Application.Inputbox just before the userform is closed. I have declared the variable, MyYear, as Public in a general module, but it comes up defined as Empty when the next userform appears. I used the Application,Inputbox method so I could force the end-user to input a year, or exit the sub if they cancelled the operation, so I had to Dim MyYear as Variant. Is this why the variable won't be retained by the Public declaration? I have tried: Public MyYear As Variant but have no more luck than any other method. I have other variables in the general module that are coming through just fine, but none of them are created using an input box. Thanks in advance for any and all suggestions (including, "stop writing code."), and let me know if a snippet of my code would help. Paul |
Unable to pass variable between Userforms
Private Sub CommandButton1_Click()
Dim dum As Variant dum = Application.InputBox("enter 4 digit year:", _ Default:=Year(Date), Type:=1) If VarType(dum) = vbBoolean Then MsgBox "No year entered, quitting" Exit Sub End If MyYear = CLng(dum) Unload Me DoEvents 'MsgBox MyYear End Sub In a general module: Public MyYear as Long worked for me. -- Regards, Tom Ogilvy "PGM" wrote: I have thoroughly searched the group for an answer to this problem, but nothing seems to fit the bill. I have created a userform that allows the user to select a variety of options in order to process incoming data files. Since our group is currently in the middle of two different processing years, I need to have the user indicate the year in which they are working. This is done with an Application.Inputbox just before the userform is closed. I have declared the variable, MyYear, as Public in a general module, but it comes up defined as Empty when the next userform appears. I used the Application,Inputbox method so I could force the end-user to input a year, or exit the sub if they cancelled the operation, so I had to Dim MyYear as Variant. Is this why the variable won't be retained by the Public declaration? I have tried: Public MyYear As Variant but have no more luck than any other method. I have other variables in the general module that are coming through just fine, but none of them are created using an input box. Thanks in advance for any and all suggestions (including, "stop writing code."), and let me know if a snippet of my code would help. Paul |
Unable to pass variable between Userforms
Thanks again, Tom!
|
All times are GMT +1. The time now is 01:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com