Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default User form varible passing

In my VBA module "module1" i have a global varible

Private global_var1 as boolean
I initialize it in the main Subroutine
global_var1 = false
Then I call my userform, which has a cmdbtn "Doit"
With Question_Form
Load Question_Form
.Show
End With
My userform cmdbtn code is
Private Sub Always_Btn_Click()
global_var1 = True
Question_Form.Hide
End Sub

However, when my userform returns "global_var1" remains = false

How do i pass global_var1 back to module1?
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default User form varible passing

Does the "main Subroutine" get run every time that you show your UserForm?
If so, you are probably re-initializing the global variable every time.
Since a Boolean variable automatically initializes on creation as False,
there is no need to deliberately initialize it to this value... try removing
the global_var1=False statement from your "main Subroutine" and see it that
makes a difference.

Rick


"miek" wrote in message
...
In my VBA module "module1" i have a global varible

Private global_var1 as boolean
I initialize it in the main Subroutine
global_var1 = false
Then I call my userform, which has a cmdbtn "Doit"
With Question_Form
Load Question_Form
.Show
End With
My userform cmdbtn code is
Private Sub Always_Btn_Click()
global_var1 = True
Question_Form.Hide
End Sub

However, when my userform returns "global_var1" remains = false

How do i pass global_var1 back to module1?
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default User form varible passing

'lcaretto' spotted the real problem... you Dim'med the global variable as
Private (I completely overlooked this), thus restricting its scope to code
in its Module only.

However, the point I made about the Boolean variable being initialized to
False at creation (so you don't have to initialize it manually) is still
valid.

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
Does the "main Subroutine" get run every time that you show your UserForm?
If so, you are probably re-initializing the global variable every time.
Since a Boolean variable automatically initializes on creation as False,
there is no need to deliberately initialize it to this value... try
removing the global_var1=False statement from your "main Subroutine" and
see it that makes a difference.

Rick


"miek" wrote in message
...
In my VBA module "module1" i have a global varible

Private global_var1 as boolean
I initialize it in the main Subroutine
global_var1 = false
Then I call my userform, which has a cmdbtn "Doit"
With Question_Form
Load Question_Form
.Show
End With
My userform cmdbtn code is
Private Sub Always_Btn_Click()
global_var1 = True
Question_Form.Hide
End Sub

However, when my userform returns "global_var1" remains = false

How do i pass global_var1 back to module1?
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default User form varible passing

The Subroutine only runs once
I have now set my global_var1 as follows:
When ' global_var1 is comes back from "Question_form" ' global_var1 is = False

Dim global_var1 as boolean

Sub module1
' global_var1 = false ' global_var1 is = False, auto initilized
With Question_Form
Load Question_Form
.Show
End With
ans = global_var1 ' global_var1 is = False
End Sub ' module1

My userform cmdbtn code is

Private Sub Doit_Btn_Click()
global_var1 = True 'global_var1 is = False
Question_Form.Hide 'global_var1 is = True
End Sub




"Rick Rothstein (MVP - VB)" wrote:

'lcaretto' spotted the real problem... you Dim'med the global variable as
Private (I completely overlooked this), thus restricting its scope to code
in its Module only.

However, the point I made about the Boolean variable being initialized to
False at creation (so you don't have to initialize it manually) is still
valid.

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
Does the "main Subroutine" get run every time that you show your UserForm?
If so, you are probably re-initializing the global variable every time.
Since a Boolean variable automatically initializes on creation as False,
there is no need to deliberately initialize it to this value... try
removing the global_var1=False statement from your "main Subroutine" and
see it that makes a difference.

Rick


"miek" wrote in message
...
In my VBA module "module1" i have a global varible

Private global_var1 as boolean
I initialize it in the main Subroutine
global_var1 = false
Then I call my userform, which has a cmdbtn "Doit"
With Question_Form
Load Question_Form
.Show
End With
My userform cmdbtn code is
Private Sub Always_Btn_Click()
global_var1 = True
Question_Form.Hide
End Sub

However, when my userform returns "global_var1" remains = false

How do i pass global_var1 back to module1?
Thanks




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default User form varible passing

Try making global_var1 a public variable so that it will be visible outside
of module1.

"miek" wrote:

In my VBA module "module1" i have a global varible

Private global_var1 as boolean
I initialize it in the main Subroutine
global_var1 = false
Then I call my userform, which has a cmdbtn "Doit"
With Question_Form
Load Question_Form
.Show
End With
My userform cmdbtn code is
Private Sub Always_Btn_Click()
global_var1 = True
Question_Form.Hide
End Sub

However, when my userform returns "global_var1" remains = false

How do i pass global_var1 back to module1?
Thanks



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
Passing Array of User Defined Type to Form dunnerca Excel Programming 4 December 23rd 07 09:22 PM
User Form value passing problem [email protected] Excel Programming 2 August 9th 06 05:19 PM
PASSING DATA FROM USER FORM TO EXCEL SPREADSHEET No Name Excel Programming 12 January 7th 04 01:36 PM
passing a range to a user defined function using a form davek Excel Programming 1 December 24th 03 07:40 AM
Passing Text from User Form to Spreadsheet Betsy[_2_] Excel Programming 1 August 6th 03 02:33 AM


All times are GMT +1. The time now is 07:04 AM.

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"