Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Transfer variable between macros

I am using a userform to create an order for stock. Variables are used
during initialization, ie stklvl = whatever the max stock level is for that
item.

The user then enters the quantity on hand. When the user presses the enter
key, the following macro executes:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = Str(stklvl) - Str(TextBox1)
End If
End Sub


Textbox2 is the difference between max stock level (stklvl) and quantity on
hand.

How do I transfer the value of stklvl from the initialization macro to this
macro so I can compute the difference?

Thanks,
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Transfer variable between macros

You need to have stklvl declared as a public variable.

If you currently have the line "Dim stklvl" in the initialisation macro,
delete it. Then, before that macro type:

Public stklvl as Variant

"WLMPilot" wrote:

I am using a userform to create an order for stock. Variables are used
during initialization, ie stklvl = whatever the max stock level is for that
item.

The user then enters the quantity on hand. When the user presses the enter
key, the following macro executes:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = Str(stklvl) - Str(TextBox1)
End If
End Sub


Textbox2 is the difference between max stock level (stklvl) and quantity on
hand.

How do I transfer the value of stklvl from the initialization macro to this
macro so I can compute the difference?

Thanks,
Les

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Transfer variable between macros

Hi,

Declare the variable as public, set syklvl in the initialise code and it
will pass to your keydown code

Public stklvl As Long
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = stklvl - Val(TextBox1)
End If
End Sub


Private Sub UserForm_Initialize()
stklvl = 99
End Sub


Mike

"WLMPilot" wrote:

I am using a userform to create an order for stock. Variables are used
during initialization, ie stklvl = whatever the max stock level is for that
item.

The user then enters the quantity on hand. When the user presses the enter
key, the following macro executes:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = Str(stklvl) - Str(TextBox1)
End If
End Sub


Textbox2 is the difference between max stock level (stklvl) and quantity on
hand.

How do I transfer the value of stklvl from the initialization macro to this
macro so I can compute the difference?

Thanks,
Les

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Transfer variable between macros

Thanks, will give it a shot



"Sam Wilson" wrote:

You need to have stklvl declared as a public variable.

If you currently have the line "Dim stklvl" in the initialisation macro,
delete it. Then, before that macro type:

Public stklvl as Variant

"WLMPilot" wrote:

I am using a userform to create an order for stock. Variables are used
during initialization, ie stklvl = whatever the max stock level is for that
item.

The user then enters the quantity on hand. When the user presses the enter
key, the following macro executes:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = Str(stklvl) - Str(TextBox1)
End If
End Sub


Textbox2 is the difference between max stock level (stklvl) and quantity on
hand.

How do I transfer the value of stklvl from the initialization macro to this
macro so I can compute the difference?

Thanks,
Les

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Transfer variable between macros

Thanks, will give it a shot

"Mike H" wrote:

Hi,

Declare the variable as public, set syklvl in the initialise code and it
will pass to your keydown code

Public stklvl As Long
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = stklvl - Val(TextBox1)
End If
End Sub


Private Sub UserForm_Initialize()
stklvl = 99
End Sub


Mike

"WLMPilot" wrote:

I am using a userform to create an order for stock. Variables are used
during initialization, ie stklvl = whatever the max stock level is for that
item.

The user then enters the quantity on hand. When the user presses the enter
key, the following macro executes:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
If KeyCode = 13 Or KeyCode = 9 Then
TextBox2 = Str(stklvl) - Str(TextBox1)
End If
End Sub


Textbox2 is the difference between max stock level (stklvl) and quantity on
hand.

How do I transfer the value of stklvl from the initialization macro to this
macro so I can compute the difference?

Thanks,
Les

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
Transfer variable to user Form jlclyde Excel Discussion (Misc queries) 2 April 23rd 10 08:25 PM
Transfer Variable from Form to Module Gleam Excel Programming 2 September 6th 07 05:54 AM
transfer a variable balance from one worksheet to the next cariad 61 New Users to Excel 4 July 31st 07 11:28 PM
how do i transfer existing excel macros to a new computer? rwr2333 Excel Discussion (Misc queries) 2 July 23rd 05 02:30 AM
How do I transfer macros in excel between two computers? diningdesk Excel Discussion (Misc queries) 1 June 28th 05 04:54 PM


All times are GMT +1. The time now is 12:39 AM.

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

About Us

"It's about Microsoft Excel"