ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Transfer Variable from Form to Module (https://www.excelbanter.com/excel-programming/396937-transfer-variable-form-module.html)

Gleam

Transfer Variable from Form to Module
 
I am having problems transferring a variable from a form back to a module.
My module is:

Public invP, vP
Sub Mod()
..
..
UserForm6.Show
MsgBox invP & vP
..
end sub

Private Sub CommandButton1_Click()
..
invP = ListBox1.ListIndex + 1
vP = ListBox2.ListIndex + 1
..
end sub

In the routine CommandButton1 invP=1 and vP=3
when the control returns to the routine Mod they both equal zero.
Any ideas why and how to make them behave?

JNW

Transfer Variable from Form to Module
 
I imagine you have already checked this, but is anything in the listbox? If
so, has anything been selected before clicking the button?

--
JNW


"Gleam" wrote:

I am having problems transferring a variable from a form back to a module.
My module is:

Public invP, vP
Sub Mod()
.
.
UserForm6.Show
MsgBox invP & vP
.
end sub

Private Sub CommandButton1_Click()
.
invP = ListBox1.ListIndex + 1
vP = ListBox2.ListIndex + 1
.
end sub

In the routine CommandButton1 invP=1 and vP=3
when the control returns to the routine Mod they both equal zero.
Any ideas why and how to make them behave?


Gleam

Transfer Variable from Form to Module
 
Thank you for the ideas - code for cancel button had been duplicated in code
for OK button - so code was setting to zero!

"JNW" wrote:

I imagine you have already checked this, but is anything in the listbox? If
so, has anything been selected before clicking the button?

--
JNW


"Gleam" wrote:

I am having problems transferring a variable from a form back to a module.
My module is:

Public invP, vP
Sub Mod()
.
.
UserForm6.Show
MsgBox invP & vP
.
end sub

Private Sub CommandButton1_Click()
.
invP = ListBox1.ListIndex + 1
vP = ListBox2.ListIndex + 1
.
end sub

In the routine CommandButton1 invP=1 and vP=3
when the control returns to the routine Mod they both equal zero.
Any ideas why and how to make them behave?



All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com