Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PGM PGM is offline
external usenet poster
 
Posts: 5
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
PGM PGM is offline
external usenet poster
 
Posts: 5
Default Unable to pass variable between Userforms

Thanks again, Tom!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass variable from one workbook to another calebjill Excel Discussion (Misc queries) 2 January 28th 09 07:38 PM
Pass variable to macro Jason Morin Excel Programming 2 November 28th 05 04:13 PM
Pass a variable into a range? Ian Fleming[_2_] Excel Programming 1 September 7th 05 09:45 AM
Application.OnTime -- Unable to Pass Macro with Numeric Parameter Butaambala Excel Programming 7 June 7th 05 10:55 PM
How to pass variable value between macros BCS Excel Programming 0 July 25th 03 08:01 PM


All times are GMT +1. The time now is 07:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"